### Math errors. Loops problem solved.

I'm just writing this program based off some things we have been doing in chemistry. I couldn't get it to go to choice two without going through choice one. So I changed some code and used strings. Now I'm getting the error 'else' without a previous 'if'

I just want to know how to get it to go to choice 2 ... any help is appreciated. (sorry for being a noob)
EDIT:
You guys rock! Thanks so much, I'm having trouble with trying to figure out the remainders now. The program runs good without the d1 and the % to find variable. When I added it, it skips steps and whatnot. Any idea on how I can get remainder with answer. (I updated code)

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485`` ``````#include #include #include #include #include using namespace std; //Was getting error of the having variables undefined // MISSING THE SECOND PRESSURE INT int a; int b; int c; int d; int d1; //MISSING THE SECOND VOLUME INT int pressureone; int volume; int pressuretwo; int answer; int main() { cout << "Boyles Law" << endl; cout << "Are you missing the pressure or volume?" << endl; string choice1; cout << "Enter, pressure or volume to continue" << endl; getline (cin, choice1); if(choice1=="pressure") { int a; cout << "Enter the pressure" << endl; cin >> a; int b; cout << "Enter the first volume" << endl; cin >> b; int c; cout << "Enter the second volume" << endl; cin >> c; d = a * b / c ; d1 = a + b % c; cout << "The missing pressure is: "; cout << d << endl; cout << d1 << endl; } else if(choice1=="volume") { int pressureone; cout << "Enter the first pressure" << endl; cin >> pressureone; int volume; cout << "Enter the volume" << endl; cin >> volume; int pressuretwo; cout << "Enter the second pressure" << endl; cin >> pressuretwo; int answer; answer = pressureone * volume / pressuretwo; cout << answer << endl; } else { cout << "Error:1" << endl; system("PAUSE"); cout << " Please enter; volume or pressure\n"; string choice1; cout << "I'm missing a pressure." << endl; cout << "I'm missing a volume." << endl; getline (cin, choice1); } return 0; }``````
Last edited on
You're missing the braces after the first if statement.
 ``12345678`` ``````if() { } else { }``````
 ``1234567891011121314151617`` `````` if(choice1=="pressure") { int a; cout << "Enter the pressure" << endl; cin >> a; int b; cout << "Enter the first volume" << endl; cin >> b; int c; cout << "Enter the second volume" << endl; cin >> c; d = a * b / c ; cout << "The missing pressure is: "; cout << d << endl; }``````