why is their an error

0 votes
asked May 3 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";
    }
    return 0;
}

1 Answer

0 votes
answered May 3 by LiOS (5,120 points)
To compare if it's equal, you should use == and === for data type check too. Also, for char put, the character within to compare within ' '. Also, you should implement error checking since when taking a value, you can enter anything and it will carry on. Simply, check if it's y or n else error and ask for the value again etc.

#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";
    }
    return 0;
}
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.
...