0

Hey everyone, I'm just now learning c++ and was wondering if there was a way to loop this program so that I don't have to copy and paste it. I got it to work, but I was just curious if there was another way to do it. it just does simple math really. Thanks in advance everyone! oh, and it runs in the command prompt window, because i can't do anything else yet haha. I have all of the semi-colons when i declared the variables because it wouldn't compile without them for some reason. Sorry it's so long.

```
/*
Pick a problem and solve
*/
#include <iostream>
using namespace std;
int main()
{
int perimiter;
int area;
double addition;
double multiplication;
double subtraction;
double division;
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
double i;
double j;
double k;
double l;
int; 2;
double result;
int x;
int; 0;
int; 3;
int; 4;
int; 5;
int; 1;
int; 6;
int; 7;
cout << "Hello, please pick a type of problem from the list. Please use the number of n each: ";
cout << "1. perimiter, 2. area, 3. addition, 4. multiplication, 5. subtraction,n 6. division, 7. Quit program. ";
cin >> x ;
if(x == 1) cout << "Enter the length: ";
if(x==1) cin >> a;
if(x==1)cout << "enter the width: ";
if(x==1)cin >> b;
if(x==1) cout << "The perimiter is: ";
if(x==1) cout << a+a+b+b;
if(x == 2)
cout << "enter the length: ";
if(x == 2) cin >> c;
if(x == 2) cout << "Enter the width: ";
if(x == 2) cin >> d;
if(x == 2)cout << "The area is: ";
if(x == 2)cout << c*d;
if(x == 3) cout << "Enter the first number: ";
if(x == 3) cin >> e;
if(x == 3) cout << "Enter the second number: ";
if(x == 3) cin >> f;
if(x == 3) cout << "The solution is: ";
if(x == 3) cout << e+f;
if(x == 4) cout << "Enter the first number: ";
if(x == 4) cin >> g;
if(x == 4) cout << "Enter the second number: ";
if(x == 4) cin >> h;
if(x == 4) cout << "The solution is: ";
if(x == 4) cout << g*h;
if(x == 5) cout << "Enter the first number: ";
if(x == 5) cin >> i;
if(x == 5) cout << "Enter the second number: ";
if(x == 5) cin >> j;
if(x == 5) cout << "The solution is: ";
if(x == 5) cout << i-j;
if(x == 6) cout << "Enter the top/first/outer number: ";
if(x == 6) cin >> k;
if(x == 6) cout << "Enter the bottom/second/inner number: ";
if(x == 6) cin >> l;
if(x == 6) cout << "The answer is: ";
if(x == 6) cout << k/l;
while(x<7){cout << "n1. perimiter, 2. area, 3. addition, 4. multiplication, 5. subtraction, 6. division, 7. Quit program. ";
cin >> x ;
if(x == 1) cout << "Enter the length: ";
if(x==1) cin >> a;
if(x==1)cout << "enter the width: ";
if(x==1)cin >> b;
if(x==1) cout << "The perimiter is: ";
if(x==1) cout << a+a+b+b;
if(x == 2)
cout << "enter the length: ";
if(x == 2) cin >> c;
if(x == 2) cout << "Enter the width: ";
if(x == 2) cin >> d;
if(x == 2)cout << "The area is: ";
if(x == 2)cout << c*d;
if(x == 3) cout << "Enter the first number: ";
if(x == 3) cin >> e;
if(x == 3) cout << "Enter the second number: ";
if(x == 3) cin >> f;
if(x == 3) cout << "The solution is: ";
if(x == 3) cout << e+f;
if(x == 4) cout << "Enter the first number: ";
if(x == 4) cin >> g;
if(x == 4) cout << "Enter the second number: ";
if(x == 4) cin >> h;
if(x == 4) cout << "The solution is: ";
if(x == 4) cout << g*h;
if(x == 5) cout << "Enter the first number: ";
if(x == 5) cin >> i;
if(x == 5) cout << "Enter the second number: ";
if(x == 5) cin >> j;
if(x == 5) cout << "The solution is: ";
if(x == 5) cout << i-j;
if(x == 6) cout << "Enter the top/first/outer number: ";
if(x == 6) cin >> k;
if(x == 6) cout << "Enter the bottom/second/inner number: ";
if(x == 6) cin >> l;
if(x == 6) cout << "The answer is: ";
if(x == 6) cout << k/l;}
if(x == 7) return 0;
}
```

*Edited 3 Years Ago by happygeek*: fixed formatting