What is expected unqualified-id

omg lol im tired of this error msg. Can someone tell me what to do to avoid it plz? In almost every program I try to make, It is an error. Btw, It is alm always on the "{" thingy. The error is on line 15, but this is only an ex. program, in many more it does this. Tysm 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

#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";

}
Last edited on
Your main functions ends at line 13

A global string variable named 'answar' is declared on line 14

Line 15 opens a new code block -- but that code block does not belong to any namespace/class/function, so you get the error.

Then lines 16-24 are executable code but they're not inside any function, so that is also an error.


Was you intent to create a new function? If so you need to give it parenthesis (and no semicolon):

1
2
3
4
std::string answar()  // <- now it's a function
{
   //.. code in here
}
This is the exact code you posted on your other thread. We've already fixed it, time to go now.
disch; thank you soo soo much dude. You were a huge help, and taught me! Thanks man I really appreciate it :)
Topic archived. No new replies allowed.