| | |
how to display wrong input if i using switch??
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 72
Reputation:
Solved Threads: 1
i need help with this very simple question....
the default in this program will just display the wrong input
if the input entered by user is different with the data type of the variable which is char..
but not if the user entered the the word which is the character is located in front of the word...
in my program, if the user entered apple instead of 'a',this program will still print that i'm in the red team...
I want this program to display the input error..
this is my code :
the default in this program will just display the wrong input
if the input entered by user is different with the data type of the variable which is char..
but not if the user entered the the word which is the character is located in front of the word...
in my program, if the user entered apple instead of 'a',this program will still print that i'm in the red team...
I want this program to display the input error..
this is my code :
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main () { char answer; cout<<"Enter Your Team :"; cin>>answer; switch (answer) { case 'a' : cout<<"You in the Red Team"; break; case 'b' : cout<<"You in the blue team"; break; default : cout<<"wrong input"; break; } }
0
#2 Nov 6th, 2009
Then you should take the input as a string. Then if the size of the string is
greater than 1 then display an error message, else compare it with a or b.
Doing this way you would have to use if/else. This isn't that bad if you
don't have many cases.
greater than 1 then display an error message, else compare it with a or b.
Doing this way you would have to use if/else. This isn't that bad if you
don't have many cases.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
![]() |
Similar Threads
- Program Keeps reading wrong input (C)
- Writing a file input and output program. (C++)
- display in alphabetical order using singly linked list? (C)
- Calculator project (C++)
- Display user input in new window (VB.NET)
- Lookup tables - how to perform a switch using a string (C++)
- can't display the output! can somebody help me?!! PLS.. (C)
- validating input problem (C)
- Trying to remember !@#$%# (C++)
Other Threads in the C++ Forum
- Previous Thread: Delano
- Next Thread: C++, Visual C++ or Java for Win32API firewall application?
Views: 209 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






