I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

c++,binary calculator.need help!!!!

joey_batusin\′s Photo
10 Oct 08, 3:08AM
(1 reply)
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();
}
john\′s Photo
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'.
Currently you need to be logged in to leave a message.