Insert a Loop?

Hello.
I'm trying to finalize my little program here, and I only need one last thing.
I've got a code for a loop, but I have no idea where to insert it.


1
2
3
4
5
6
7
8
int main() {
     string response;
     while(response == "continue") {
          //your code
          cout<<endl<<"Type 'continue' to continue, anything else to exit: ";
          cin>>response;
     }
}


And the code for my program:
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
55
56
57
58
59
60
61
int addition(int x, int y);
#include <conio.h>
#include <iostream>
#pragma hdrstop

using namespace std;


int addition (int, int);
void showResult(int);

int addition(int x, int y) {
     return x + y;   //change to + - * or /.
}

int subtract(int x, int y) {
     return x - y;   //change to + - * or /.
}

int multiplication(int x, int y) {
     return x * y;   //change to + - * or /.
}

int dividation(int x, int y) {
     return x / y;   //change to + - * or /.
}

void showResult(int res) { 
     cout<<"The result is "<< res << endl;
}


int main(int argc, char **argv, int res) {
     int x, y, result;
     char calcer;
     cout << endl <<"Enter the first value:";
     cin >> x;
     
     cout << endl <<"Enter your calctype\n + for Addition, - for Subtraction\n*     fpr multiplication and / for division:";
     cin >> calcer;  
     cout <<"Enter the second value: ";
     cin >> y;
     if (calcer == '+') {
           result = addition(x, y);
           showResult(result);
     } else if (calcer == '-') {
           result = subtract(x, y);
           showResult(result);
     } else if (calcer == '*') {
           result = multiplication(x, y);
           showResult(result);
     } else if (calcer == '/') {
           result = dividation(x, y);
           showResult(result);
     } else {
         cout<<"Incorrect calculation type selected. Please restart the program.\n";
     } 
     cout << endl << endl << "Press any key to continue...";
     getch();
     return 0;
}


Any help would be greatly appreciated!
Last edited on
Hey if you put that code in you would get a heap of errors. What you need to do is put #include<string> at the very beggining to be able to use string
Topic archived. No new replies allowed.