why is their an error

0 votes
asked May 4 by Ivana Ogunlaja (610 points)

#include <iostream>
using namespace std;

int main()
{
    char w;
    cout << "Welcome to the forest adventure game.\n";
    cout << "You can bring one object.\n";
    cout << " what object do you choose enter(f) for food (m) for map and (s) for sleeping bag.\n";
    cin >> w;
    cout << "You hear a sound do you go towards it enter (y) or (n)";//y means yes n means no
    char t;
    cin >> t;
    if(t=='y'){
        cout << "The sound gets louder and then it srikes you get killed by the lion you lose the game";
    }if(t=='n'){
        cout << "The sound gets quiter but now you are lost enter (c) to stop and shout for help enter (r) to carry on running";
    char y;
    cin >> y;
    if(y== 'r'){
        cout << "You find somebody homeless he says I will help you if you give me a sleeping bag.\n"
    }if(w=='s'){
        cout << "Lukily you choose correctly.\n"
        ;cout << "You win the game"
    }if(w== 'm'){
        cout << "You lose"
    }if(w== 'f'){
        cout << "You lose"
    
    }
    }
    }
    }
    }
    return 0;
}

main.cpp: In function ‘int main()’:
main.cpp:22:5: error: expected ‘;’ before ‘}’ token
     }if(w=='s'){
     ^
main.cpp:25:5: error: expected ‘;’ before ‘}’ token
     }if(w== 'm'){
     ^
main.cpp:27:5: error: expected ‘;’ before ‘}’ token
     }if(w== 'f'){
     ^
main.cpp:30:5: error: expected ‘;’ before ‘}’ token
     }
     ^
main.cpp: At global scope:
main.cpp:33:5: error: expected declaration before ‘}’ token
     }

1 Answer

+2 votes
answered May 4 by LiOS (5,120 points)
selected May 5 by Ivana Ogunlaja
 
Best answer
Mostly too many } and too little ;

Space out code like below too help.

#include <iostream>
using namespace std;

int main()
{
    char w;
    cout << "Welcome to the forest adventure game.\n";
    cout << "You can bring one object.\n";
    
    cout << " what object do you choose enter(f) for food (m) for map and (s) for sleeping bag.\n";
    cin >> w;
    
    cout << "You hear a sound do you go towards it enter (y) or (n)";//y means yes n means no
    char t;
    cin >> t;
    
    if(t=='y'){
        cout << "The sound gets louder and then it srikes you get killed by the lion you lose the game";
    }
    
    if(t=='n'){
        cout << "The sound gets quiter but now you are lost enter (c) to stop and shout for help enter (r) to carry on running";
    }
    
    char y;
    cin >> y;
    
    if(y== 'r'){
        cout << "You find somebody homeless he says I will help you if you give me a sleeping bag.\n";
    }
    
    if(w=='s'){
        cout << "Lukily you choose correctly.\n";
        cout << "You win the game";
    }
    
    if(w== 'm'){
        cout << "You lose";
    }
    
    if(w== 'f'){
        cout << "You lose";
    }

    return 0;
}
commented May 5 by Ivana Ogunlaja (610 points)
it works but I added some stuff like you did and it didn't give me the output I want should I ask the question again with my code I added
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...