Error code

Hello.
I am making a program for adding text to a file and more.
I get this error code: "expected primary-expression before 'else'" and "expected ';' before 'else'" at these rows in a loop:
1
2
3
4
5
6
    do {
    cin >> yn;
    if (yn=="y") {makefile(); cout << "Creating the file " << filename; looperthingy=true;}
    else if (yn=="n") {cout << "Answer is No, cancelling program."; looperthingy=true; entergo=false;} //Error at this row
    else cout << "Please write y or n.\n"; //And this row
    } while (looperthingy==false);

Any help is welcome.
//MisterArrow
It seems you're missing some braces.
Line 5: else { .... }
isnork, no, cause that is just one command/function/whateveryouwannacallit and that don't need braces... OH i found the problem...

i added a ; too much in the code but it (somehow) didn't make it to the site...
line 3
if (yn=="y") {makefile(); cout << "Creating the file " << filename; looperthingy=true;}; //THERE<<<
I am sorry for taking up place in the forums :)
No need to apologize. However please space out your code for legibility! It would be much easier to read this program if it was written like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
do 
{
    cin >> yn;
    if(yn=="y") 
    {
		makefile(); 
		cout << "Creating the file " << filename; 
		looperthingy=true;
    }
    else if(yn=="n") 
    {
		cout << "Answer is No, cancelling program."; 
		looperthingy=true; 
		entergo=false;
    } //Error at this row
    else 
		cout << "Please write y or n.\n"; //And this row
} while(looperthingy==false);
Last edited on
Oh that is a good idea! Thank you! I will start doing that.
Topic archived. No new replies allowed.