0
#include <iostream.h>
int main(void){

int a;
int b;
int c;

cin >> a;
cin >> b;
c = a+b;

cout << c;

return 0; 

}

I am trying to create an "addition machine". As of now, after I run the program, I can input a number and then another number, and it gives me the sum. If I input 10 and a 12, it automatically adds it up to 22. The problem is that I can't do more than 1 sum like that. I want to make it go continuously. I want it so I can input 10 and 12 and get 22 and input 15 to get 37 and 13 to get 50. I want it to terminate when I type in 0 or something not a letter. My problems with these type of programs are:

1. I don't know how to make them continue after 1 input.
2. I don't know how to choose when they terminate.

I am very knew at programming, and I need help. If you choose to, you can give me examples of the same concept, so I can apply the knowledge to this. The problem is I never did anything near this and my textbook doesn't even show how to make the input thing continue.

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by vishesh
0

Well, simplest way for that you could create another integer called sum. Then you may create a loop and each time ask for input, place a condition to terminate:

while( (choice != 'N') && (choice != 'n') )
     {
         cout << "\nENTER NUMBER: ";
         cin  >> a;
         sum += a;
         cout << "\nSUM IS NOW: " << sum;
         cout << "\n\nADD MORE (Y/N): ";
         cin >> choice;
     }
0

Well, simplest way for that you could create another integer called sum. Then you may create a loop and each time ask for input, place a condition to terminate:

while( (choice != 'N') && (choice != 'n') )
     {
         cout << "\nENTER NUMBER: ";
         cin  >> a;
         sum += a;
         cout << "\nSUM IS NOW: " << sum;
         cout << "\n\nADD MORE (Y/N): ";
         cin >> choice;
     }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.