Adding a loop to a calculator program

I am having trouble with adding a loop to this calculator program. The prompt says to add a while ( ) loop and also add one more int variable. It needs to be able to go through the original program, then ask if you want to do another task and repeat the program again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  // Include the iostream library
#include <iostream>
 
//Use the standard namespace
using namespace std;
 
void main ( )
{
   // Declare the variables
   float Number_1;
   float Number_2;
   float Result;
   int Which_Calculation;
 
   // Give instructions
   cout << "Choose a task. Press 1 to add, 2 to subtract, 3 to multiply, and 4 to divide." << endl;
   cin >> Which_Calculation;
 
   // Get numbers
   cout << "Please enter the first number." << endl;
   cin >> Number_1;
   cout << "Please enter the second number." << endl;
   cin >> Number_2;
 
   if (Which_Calculation == 1)
   {
      // Calculate the result
      Result = Number_1 + Number_2;
   }
   
   if (Which_Calculation == 2)
   {
      // Calculate the result
      Result = Number_1 - Number_2;
   }
   
   if (Which_Calculation == 3)
   {
      // Calculate the result
      Result = Number_1 * Number_2;
   }
   
   if (Which_Calculation == 4)
   {
      // Calculate the result
      Result = Number_1 / Number_2;
   }
   // Print the answer is...
   cout << "The answer is..." << endl;
 
   //Print the result
   cout << Result << endl;
   system ("PAUSE");
}


This program runs fine on its own, but after trying several times to figure it out, I just cant seem to put a loop into it.
Last edited on
This topic has been covered many times.

http://www.cplusplus.com/search.do?q=loop+calculator
Topic archived. No new replies allowed.