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"...
#include<iostream>
#include<cstdlib>
usingnamespace 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"<<endl;
}
system("PAUSE");
return 0;
}
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. . .
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.. :
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
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)
{
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<<rev[zero2]<<endl;
zero2++; // zero2 ++ so adding the address first,second,third . . .
zero--; // zero -- so the last -1 , last -2 and so on
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