so im starting to learn some loops... its a rocky start but in theory i think this should work im trying to get a repetitive addition program going.
basically its a simple this + that program but i am focusing on making it continue instead of exiting every single time i finish calculating
so i tried giving it a choice to exit or not to exit...but it doesnt seem to be working
2) also this is off topic but i was surprised when result=a+b is not the same thing as a+b=result.... i think i understand that is like that because we are trying to define result first... but i was still a little surprised by that
#include <iostream>
usingnamespace std;
int main()
{
int a,b,result;
char cont;
do{
cout<<" Enter number 1: ";
cin>> a;
cout<<" enter number 2: ";
cin>>b;
result=a+b;
cout<<" Your answer is: "<<result;
cout<<" Continue? (y/n)";
cin>>cont;
} while (cont==y);
return 0;
}
2) also this is off topic but i was surprised when result=a+b is not the same thing as a+b=result.... i think i understand that is like that because we are trying to define result first... but i was still a little surprised by that
when you type in C++ A = B; you are telling give to A the value of B
result = a+b means get the value of a+b and assign it to result, a+b = result wouldn't make much sense ( although it may be right on some weird circumstances )
hmm thank you it worked...however it does not recognise the "n"...i thought that by the logic of my code anyhting other than "y" entered will stop the program
ooohh thats a nice use of or.... can one use that as many times in the same parenthesis? of an action? also im not sure what cin.clear does? im assuming it clears the screen of my previous calculations after i have used the program a few times?
EDIT: hmm i tested your code and cin.clear() does not do what i thought it did...
you mean enter a character into the addition process of the program? itll go all crazy
How do I fix that? have been making programs to make while and do loops, but whenever I press a letter, instead of the numbers, my program loops and loops until I kill the process. How can I make the program only choose integers, and not letters?
thanks..