WHy is this not working?

A simple asking program

Page 1 of 1

1 Replies - 394 Views - Last Post: 07 April 2010 - 03:33 PM Rate Topic: -----

#1 Guest_tevin*


Reputation:

WHy is this not working?

Posted 07 April 2010 - 03:28 PM

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string myname;

int main() {
    string mood;
cout << "Hello How are you, can you please provide your name?: " << endl ;
cin >> myname;
cout << " Hello " << myname << " How are you?" << endl;
cin >> mood;

if (mood = "Good")
{
    cout << " Good i am happy you feel well";


}else {

 cout << " Why do you feel bad? ";
}

 return 0;

}



Why is this program not working? I am trying to get the program to say hi and then get the name and then ask how are you with that said name [ got that down] and if the user enters good then the program executes " good i am happy you feel well" and any thing else " why do you feel bad"
 please help



Is This A Good Question/Topic? 0

Replies To: WHy is this not working?

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1074
  • View blog
  • Posts: 4,533
  • Joined: 09-June 09

Re: WHy is this not working?

Posted 07 April 2010 - 03:33 PM

a single = is an assignment operator, you want the == comparison operator. Change your if to this
if (mood =="Good")


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1