Switch Case w/no errors

Switch case w/no errors but does not work correctly

Page 1 of 1

2 Replies - 986 Views - Last Post: 11 October 2009 - 11:59 AM Rate Topic: -----

#1 hottestchica2004   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Switch Case w/no errors

Posted 11 October 2009 - 11:42 AM

I created a switch case statement, but did not come out with the correct responses. There were no errors so i was able to execute the program, but no matter what i enter i get the same default response instead of the responses I programmed in. Not sure what i did wrong.
//This program demonstrates the use of a switch statement.
#include <iostream>
using namespace std;

int main ()
{
	   int num;
	
	
	cout << "I will ask you a question and you will answer\n yes, no, or maybe"
		 " by typing in 1 for yes,\n 2 for no, or 3 for maybe." << endl;
	cout << endl;
	cout << "Would you like to dance?" << endl;
	cin >> num;
	switch (num)
   {
		   case '1': 
				cout<< "Yes" << endl;
		   break;
		   case '2':
				cout << "No" << endl;
		   break;
		   case '3':
				cout << "Maybe" << endl;
		   break;
		   default:
				 cout << "You did not enter 1, 2, or 3!" << endl;
		   break;
	}
	cin >> num;
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Switch Case w/no errors

#2 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Switch Case w/no errors

Posted 11 October 2009 - 11:45 AM

You declared a int not a char so change the case to numbers like
case 1:
break;
case 2:
break;


This post has been edited by ImaSexy: 11 October 2009 - 11:45 AM

Was This Post Helpful? 0
  • +
  • -

#3 hottestchica2004   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-October 09

Re: Switch Case w/no errors

Posted 11 October 2009 - 11:59 AM

yay i worked thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1