Created
January 26, 2013 12:54
-
-
Save sprintr/4642173 to your computer and use it in GitHub Desktop.
Using switch, case, break, default!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream.h> | |
void main(void) | |
{ | |
cout << "1 - Calculate the area of a room: " << endl; | |
cout << "2 - Convert age into seconds: " << endl; | |
cout << "3 - Convert Celcius into farenhiet: " << endl; | |
cout << "4 - Exit" << endl; | |
int choice = 0; | |
cin >> choice; | |
switch(choice) { | |
case 1: | |
int width, length, area; | |
cout << "Enter the width of the room: " << endl; | |
cin >> width; | |
cout << "Enter the length of the room: " << endl; | |
cin >> length; | |
area = width * length; | |
cout << "The area of the room: " << area << endl; | |
break; | |
case 2: | |
int age, ageSeconds; | |
cout << "Enter your age: " << endl; | |
cin >> age; | |
ageSeconds = age * 365 * 24 * 60 * 60; | |
cout << "Your age in seconds: " << ageSeconds << endl; | |
break; | |
case 3: | |
int tempC, tempF; | |
cout << "Enter the temprature in C: " << endl; | |
cin >> tempC; | |
tempF = tempC * (9/5) + 32; | |
cout << "Temprature in F: " << tempF << endl; | |
break; | |
case 4: | |
cout << "Thanks for using this application." << endl; | |
break; | |
default: | |
cout << "Enter a valid option" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment