Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can't figure out why this won't run.

C#
#include<iostream>
using namespace std;

void main ()

{

    int x;

    cout<<"Am I the best person on this earth?\n";
    cout<<"Please enter yes or no.\n";
    cin>>x;

    if (x == yes)

    {

    cout<<"You are correct, heaven welcomes you!\n";

    }

    if (x == no)

    {
        cout<<"You are incorrect, the devil will eat your soul!\n";

    }

    else

    {

        cout<<"Please answer the queston";

    }


}
Posted
Comments
[no name] 11-Aug-13 19:09pm    
It does not run because it will not compile. You have not defined what "yes" and "no" are in your code.
Ron Beyer 11-Aug-13 19:16pm    
Not to mention trying to read a string into an integer.

Quote:
Can't figure out why this won't run.

It even don't compile: you are using undefined symbols yes and no (you are also using an integer variable where a string is required).

Try:

C++
#include <iostream>
#include <string>
using namespace std;
 
int main ()
{
  string answer;
 
  cout << "Am I the best person on this earth?\n";
  cout << "Please enter 'yes' or 'no'.\n";
  cin >> answer;
 
  if (answer == "yes")
  {
    cout << "You are correct, heaven welcomes you!\n";
  }
  else if (answer == "no")
  {
    cout << "You are incorrect, the devil will eat your soul!\n";
  }
  else
  {
    cout << "Please answer either 'yes' or 'no'.";
  }
}
 
Share this answer
 
Comments
Maciej Los 12-Aug-13 4:27am    
Complete answer!
+5!
CPallini 12-Aug-13 4:32am    
Thank you again, Maciej.
ridoy 12-Aug-13 4:41am    
+5
CPallini 12-Aug-13 4:48am    
Thank you.
make variables:
C++
char yes = 'y';
char no = 'n';
 
Share this answer
 
try this
C#
int x;

cout<<"Am I the best person on this earth?\n";
cout<<"Please enter 1.yes or 0.no.\n";
cin>>x;

if (x == 1)
{

    cout<<"You are correct, heaven welcomes you!\n";

}

else if (x == 0)
{
    cout<<"You are incorrect, the devil will eat your soul!\n";

}
else
{

    cout<<"Please answer the queston";

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900