Stroustrupp PPP ch3 ex7

I am just missing something totally simple. Just started to learn C++ a few weeks ago. Haven't programmed before. I have found working code to compare mine to for this exercise and still cant figure it out. Comments on the lines i get an error im missing a '}' somewhere but i cant see it.

Thanks in advance

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
#include "std_lib_facilities.h"
int main()
{
    cout << "Please enter three words sepreated by spaces: \n";
    string val1 = " ";
    string val2 = " ";
    string val3 = " ";
    cin >> val1 >> val2 >> val3;
    cout << "Valuse read: " << val1 <<", " << val2 <<", "<<val3 <<".\n" ;
    string smallest = " ";
    string middle = " ";
    string largest = " ";
    if (val1<=val2) {
        if (val1<=val3);{
        smallest = val1;
            if (val1<=val3){
                middle = val2;
                largest = val3;
            }
                    else {
                        middle = val3;
                        largest = val2;
                }
            }
            else { // Error: Expected '}" before 'else'
                smallest = val3;
                middle = val1;
                largest = val2;
        }
    }
    else { // Error: Expected unqualified-id before 'else'
        if (val1 > va13){
            largest = val1;
            if (val2 <= val3){
                smallest = val2;
                middle = val3;
        }
            else {
                smallest = val3;
                middle = val2;
        }
    }
        else {
            smallest = val3;
            middle = val1;
            largest = val2;
        }

    }
    cout << "Values sorted " << smallest << ", " << middle <<", " << largest;
return 0;
}
Take a peek at line 14... you see that semicolon that snuck in there? Take it out.

And you have a typo on line 32. va13 should be val3. It is hard to see the difference between 1 and l (lowercase L).
Last edited on
Line 14:

You have a ;{ so remove the ;

EDIT: Got sniped.
Last edited on
Awesome thanks alot! I knew it was something small. Also I had va13 on line 32 instead of val3 but that one was easy to spot!'

edit: he even sniped me before i could reply haha
Last edited on
Topic archived. No new replies allowed.