### identify floating or alphabets

hello
i have this homework where i am implementing a code which does error checking

so basically i have 3 variables and i assigned them as integer. so my error check is asking that if i type a value for instance 1.2 it should output "X"...

any suggestions pls helpppppp!!!
 ``12345678910111213141516`` ``````#include #include using namespace std; int main() { int a; cin>>a; if(!cin) // well this { cout<<"X"<

if i understood you good
Last edited on
 ``123456789101112131415161718192021`` ``````#include #include using namespace std; int main() { float a; cin>>a; int checker; checker=a; // a=1.2 if(!cin||((checker+1)!=(a+1)&&(checker-1)!=(a+1))||a==0) // well this { cout<<"X"<

here friend hope that this helps
it basicly conversion like this loses the decimals
checker=a// so if a is 2.5 the checker will be 2
but if we add a=2 checker will be 2 also so. . .
Last edited on
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include "stdafx.h" #include #include #include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int remainder, quotient, base,i; int checker; float quotient2; cout << "Please enter a quotient: "; cin >> quotient2; checker=quotient2; if (!cin||quotient2 == 0||((checker+1)!=quotient2+1)||((checker-1)!=quotient2-1) ) { cout << "X" << endl; return 0; } quotient=quotient2; cout << "Please enter a Base: "; cin >> base; while (quotient > 0) { remainder = quotient % base; quotient /= base; cout<< remainder << endl; } cout <

HERE :P
Last edited on
it worked but give a failure error
""Run-Time Check Failure #3 - The variable 'quotient' is being used without being initialized.""
Last edited on
are you sure ?:D
i tested this code it worked good?
copy paste the above code?
did you copy this ???
***
quotient=quotient2;
***
Last edited on
yeh works perfectly i just did add quotient2 in there. but thanks alot friend..
so by now you should see that i am converting decimals to binary. so is there any way that i could output my value in reverse..
for instance denominator 12, divisor 2, i get 0011 but i want the output to be reverse of that.. so like 1100.. :

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include "stdafx.h" #include #include #include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int remainder, quotient, base,i; int checker; float quotient2; cout << "Please enter a quotient: "; cin >> quotient2; checker=quotient2; if (!cin||quotient2 == 0||((checker+1)!=quotient2+1)||((checker-1)!=quotient2-1) ) { cout << "X" << endl; return 0; } quotient=quotient2; cout << "Please enter a Base: "; cin >> base; int a[100000]; int rev[100000]; int zero=0; while (quotient > 0) { remainder = quotient % base; quotient /= base; a[zero]=remainder; cout<< remainder << endl; zero++; } cout<<":::::::::::::::\n"; int zero2=0; while(zero>0) { rev[zero2]=a[zero-1]; cout<

something like this :))
WOOOW ! my friend you are a genious ... you are really goood

well i wana have just one output. the reversed answer
xD
remove the cout in 39 line
and in 43
have fun :)
Last edited on
i swear you are very good.
so one more thing sorry.

like this is actually like an error checking homework. so at the end i will have to alter it and get all the "cin" functions removed. so can you give me alternative for "" !cin"" function pls
u ll use scanf? explain me better
i need to go ,
i will answer you later :)
give me an example before i get back,:P
ok.. wel its like an error checking homework..
where you do error check..
example.
quotient 12 base 2 output reversed 1100. true
quotient 0 base (value) invalid because its not right.true (output invalid)

again having quotient as an integer than writing a value of 1.2 which is a float n is wrong so output "X".

but you are not allow to ask user's input..
i write all my programs using argc().. so my teacher just basically insert my code into his unknown program and it goes through the error check..
get it>??? :D
its a bit hard to explain..
my friend can you pls explain the reverse thingi that you did with the output pls..
int a[100000];
int rev[100000];
int zero=0;
while (quotient > 0)
{

remainder = quotient % base;
quotient /= base;
a[zero]=remainder;
cout<< remainder << endl;

zero++;
}
cout<<":::::::::::::::\n";
int zero2=0;
while(zero>0)
{
rev[zero2]=a[zero-1];
cout<<rev[zero2]<<endl;
zero2++;
zero--;
 ``12345678910111213141516171819202122232425262728293031323334`` ``````int a[100000]; // i make a array of 100000 max elements int rev[100000]; // same int zero=0; // its the pointer of the array "a" while (quotient > 0) // this is yours { remainder = quotient % base; quotient /= base; a[zero]=remainder; // so this puts in to the array "a" 0 0 1 1 cout<< remainder << endl; zero++; // this is for what place the remainder to be example // 0 (0) // 0 (1) // 1 (2) // 1 (3) } cout<<":::::::::::::::\n"; // separates int zero2=0; // second pointer to 0 while(zero>0) // so in the first loop for 0011 the zero was adding 1+ every // time , we will use it to transfer it to the rev (reverse) array { rev[zero2]=a[zero-1]; // reverse array // the first number will be the last in the a array // the second number will be the last - 1 in the a array // and so on cout<
but if u declare this as int u cant type in characters
so u need a condition that doesnt allow float numbers and zero ?
if so just remove the '!cin' and make quotient2 to be quotient
and quotient to be quotient2.
and it shud be good for running :D
sry for my late answer
no worries my friend i fall aslee hehe :P
in my if statement. i want to have a restriction my friend.
like if its 2e2 it should continue to run the program which it is doing so, but if its for insistance .e2 i should output X
for characters?
make me an in example

in

2
2

out
0
1

in
1.2

out
X

something like that?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include "stdafx.h" #include #include #include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int remainder, quotient2, base,i; int checker; float quotient; cout << "Please enter a quotient: "; // ur value checker=quotient; if (quotient == 0||((checker+1)!=quotient+1)||((checker-1)!=quotient-1) ) { cout << "X" << endl; return 0; } quotient2=quotient; cout << "Please enter a Base: "; cin >> base; int a[100000]; int rev[100000]; int zero=0; while (quotient2 > 0) { remainder = quotient2 % base; quotient2 /= base; a[zero]=remainder; cout<< remainder << endl; zero++; } cout<<":::::::::::::::\n"; int zero2=0; while(zero>0) { rev[zero2]=a[zero-1]; cout<

Last edited on
ok don't worry about that i got it working..
but have another problem..
what does if(argc==3) mean?

what does if(argv[2][i]) ?

Topic archived. No new replies allowed.