-
Advice
Hello, please help.
I have a guy called: "TZ" and a guy called: "WY".
TZ has 1000 salary
WY has 10 salary
Input the NAME on startup, and then the program will identify either it's TZ or WY or others... using the command "switch"
CONSOLE RELATED
Thanks a lot
-
isn't it just to use the switch as usual?
Code:
#include <iostream>
using namespace std;
int main()
{
char name[2];
cout << "Please enter your name: ";
cin >> name;
switch(name[0])
{
case 'T': cout << "hi ty";
break;
case 'W': cout << "hi WY";
break;
default: cout << "hi you";
break;
}
return 0;
}
-
How come?
I declared:
how come I can't set the Value of it during
main(){}?
-
ANOTHER ONE
PHP Code:
#include <iostream>
using namespace std;
int main(){
char POS[100];
int SAL;
cout<<"Please enter your Position in Sviesoft:"<<endl;
cin>>POS;
switch(POS[0]){
case 'pddddddd':cout<<"WOW!!! PROGRAMMER, YOUR SALERY IS:"<<endl;SAL=5000;cout<<SAL<<endl;break;
case 'MANAGER':cout<<"SURE, MANAGE TOM IF YOU CAN!"<<endl;SAL=3998;cout<<SAL<<endl;break;
case 'TOMZHANG':cout<<"BOSS!!! YOU DECIDE!"<<endl;cin>>SAL;cout<<"You get! "<<SAL<<" Dollars!!"<<endl;break;
default:cout<<"I'm sorry. There's no record of your position in Sviesoft"<<endl;break;}
return 0;}
Anyone knows how to solve this?
-
#1 - putting all that code on single lines makes it very difficult to read.
#2 - You can't switch on anything except int's and char's. But only one char. switching on 'TOMZHANG' is not legal.
-
you'll need a series of if(!strcmp()) statements