c++,binary calculator.need help!!!!
c++,binary calculator.need help!!!!
please help me on my problem,,
what can i do so that after the answer were verify
it will random binary number again????
#include <iostream.h> #include <conio.h> #include <time.h> #include <stdlib.h> #include <string.h> int up; int down; int sum; char str1[100]; char str2[100]; char total[100]; char input[100]; void main() { clrscr(); randomize(); up=random(10)+1; down=random(10)+1; cout<<up; cout<<endl; cout<<down; itoa(up,str1,2); itoa(down,str2,2); cout<<endl<<endl; cout<<"Add the two binary number"; cout<<endl<<str1; cout<<endl; cout<<str2; sum=up+down; cout<<endl<<endl; cout<<"the sum"; cout<<endl<<sum; itoa(sum,total,2); cout<<endl<<endl; cout<<endl<<"The binary of sum"; cout<<endl<<total; cout<<endl<<"Enter your answer: "; cin>>input; if (!strcmp(total,input)) { clrscr(); cout<<"your answer is correct"; // after this part what will i do so that it will generate random binary numbers again?????? } else { clrscr(); cout<<"wrong"; //after this part what will i do so that it will generate random binary numbers again?????? } getch(); }
10 Oct 08, 3:12PM
Add a do-while loop to your code, i.e. the front and end should look like this
// ... what-ever you have above, prior to the main void main() { do { //... the rest of your original code goes here ... } while(1) }then this program will keep going forever. You might like to replace the '1' in 'while(1)' with a nicer condition, so for example it breaks when the user types 'q'.
Login