Plz, how do i fix this program?

the program is saying expected unqualified-id on line 15. This is sooo annoying lol have been looking for solution all day. plz help if possible I will really really appreciate it. Thank you so much in advance, and regards, Michael




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
#include <string>
#include <iostream>
std::string answer;
using namespace std;
int main()
{
    cout<< "are you dumb or smart?";
    cin>> answer;
    if (answer == "dumb")
        std::cout<< "I completely agree";
    else
        cout<<"good to hear";
}

{
    string answar;
    cout<< "If given a, b, or c, what is your favorite letter?";
    cin>>answar;
    if (answar == "c")
        cout<< "the word catastrophe starts with that letter.";
        else if (answar == "b")
        cout<<  "the word bactericide starts with that letter";
        else
        cout<< "The word apostraphe starts with that letter";
        
        }
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <string>
#include <iostream>
std::string answer;
using namespace std;
int main()
{
    cout<< "are you dumb or smart?";
    cin>> answer;
    if (answer == "dumb")
        std::cout<< "I completely agree";
    else
        cout<<"good to hear";
}


This is your program. The main function has finished. You can tell it has finished because of the closing brace, }. All the stuff after that is junk. It is not part of any function.

Take a good look at all the braces and work out where they are meant to go.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string>
#include <iostream>
std::string answer;
using namespace std;
int main()
{
    cout<< "are you dumb or smart?";
    cin>> answer;
    if (answer == "dumb")
        std::cout<< "I completely agree";
    else
        cout<<"good to hear";
    string answar;
    cout<< "If given a, b, or c, what is your favorite letter?";
    cin>>answar;
    if (answar == "c")
        cout<< "the word catastrophe starts with that letter.";
    else if (answar == "b")
        cout<<  "the word bactericide starts with that letter";
    else
        cout<< "The word apostraphe starts with that letter";
    return 0; 
}

What book did you learn this from?
xhtmix, hi, you just helped me fix my other program! :) thanks. I learned from internet mostly, few from book, too boring lol. Anyways, I tried to do it with only one pair of braces, and it had a bazillion errors. Thank you guys for the help. xhtmix, I really appreciate it you are the best!!!. Thanks again.

oh wait btw, It worked, and I added a bit, but now when It ask for name it just shows lldb as reply, but no problem sign. Thank you soo soo much xhtmix. the following 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
#include <string>
#include <iostream>
using namespace std;
string answer;
string answar;
string name;
int main()
{
    cout<< "why hello, what is your name?";
    cin>> name;
    cout<< "what a nice name:" << name;
    cout<<"\n";
    cout<< "lemme give you some questions...";
    cout<<"\n";
    cout<< "are you dumb or smart?";
    cin>> answer;
    if (answer == "dumb")
        cout<< "I completely agree";
    else if (answer == "smart")
        cout<<"good to hear";
    cout<<"\n";
     cout<<"\n";
 
    
    cout<< "If given a, b, or c, what is your favorite letter?";
    cin>>answar;
    if (answar == "c")
        cout<< "the word catastrophe starts with that letter.";
    else if (answar == "b")
        cout<<  "the word bactericide starts with that letter";
    else if (answar == "a")
        cout<< "The word apostraphe starts with that letter";
    return 0;
}
Topic archived. No new replies allowed.