# include <iostream>
usingnamespace std;
int main ()
{
int a,b,c ;
cout <<" enter ur first no. " << endl;
cin >> a;
cout <<" enter ur second no. " << endl ;
cin >> b ;
cout <<" ur ans is " << (a+b) <<endl;
scanf ("%d%",&c);
return 0 ;
}
umm ok if i want to continue this program like after d addition gets over i want the program to ask the digits for addition again ? how can i do so ?
To keep the program going keep adding more code... Am I misunderstanding your request? You could also use a loop of some kind, in that case there are a few choices like a for() loop or a while() loop or a do...while loop. How many interations do you want?
do
{
char input;// variable that stores user's choice
// enter program here
cout << "Do you want to quit?\n[Y]es [N]o/n";
cin >> input;
} while ((input == 'N') || (input == 'n'))
// Way one:
int main ()
{
// Code here...
// When we return we call the main function
return main ();
}
// Way two:
int main ()
{
// Label to go to later
StartOfMain:
// Code here...
// Go to the label
goto StartOfMain;
return 0;
}
// Way three:
int main ()
{
// A loop
// Do while:
do
{
// Code here...
} while (0 == 0);
// Or a while:
while (0 == 0)
{
// Code here...
}
// Or a for:
for (;;)
{
// Code here...
}
return 0;
}
# include <iostream>
usingnamespace std;
int main ()
{
do
{
char input;// variable that stores user's choice
// enter program here
int a,b,c ;
cout <<" enter ur first no. " << endl;
cin >> a;
cout <<" enter ur second no. " << endl ;
cin >> b ;
cout <<" ur ans is " << (a+b) <<endl;
scanf ("%d%",&c);
cout << "Do you want to quit?\n[Y]es [N]o/n";
cin >> input;
} while ((input == 'N') || (input == 'n'))
return 0 ;
}
it says 22 `input' undeclared (first use this function)
EDIT: made some changes to the program and it compiles fine..but kinda dont understand how it works..ran it after the line says do u want to continue (y/n)
if i press y nothing happens if i press n nothing happens ?
If you use the code we've posted exacty, you're program should work fine. You probably didn't put char input at line 9, and the code is written to work if you ask "Do you want to quit?" not "Do you want to continue?"