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)

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <math.h>
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.
1
2
3
4
5
6
7
8
if()
{

}
else
{

}
One thing your missing for sure is {} around your if.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
     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;
     }
Topic archived. No new replies allowed.