Here is an example of if-else statement:
#include <iostream>
using namespace std;
int main()
{
int opt;
cout << "Main Menu\n"
<< "=========\n"
<< "1. Calculator\n"
<< "2. Temp Converter\n"
<< "3. Exit program\n"
<< "Enter your selection (1,2,3): ";
cin >> opt;
if (opt == 1)
cout << "You selected option 1 - Calculator.";
else if (opt == 2)
cout << "you selected option 2 - Temp Converter.";
else if (opt == 3)
cout << "You selected option 3 - the program will end now";
else
cout << "Invalid input. Please restart program.";
return 0;
}
Comments
Post a Comment