Question #23969

11. Suppose I have a variable called num whose value has already been set. Write a switch statement that will print "One" if the value of num is 1, "Two" if the value of num is 2, and "Three" if the value of num is 3.

Expert's answer

#include <iostream>
#include <conio.h>


using namespace std;

int main()
{
int number;
cout<<"Enter number (1,2 or 3): ";
cin>>number;
switch(number){
case 1:
cout<<"One";
break;
case 2:
cout<<"Two";
break;
case 3:
cout<<"Three";
break;
}
getch();
return 0;
}

LATEST TUTORIALS
APPROVED BY CLIENTS