#include <iostream> //include header files
using namespace std;
int main () //start of main body
{
int num; //declaring integer
int control=1; //declaring integer
while(control==1)//start of loop, as long as condition is true
{
cout << "Press 1 for coffee" << endl; //writes to standard o/p
cout << "Press 2 for tea" << endl;
cout << "Press 3 for hot chocolate" << endl;
cout << "Press 4 for soft drink" << endl;
cout << "Press 5 to exit" << endl;
cin >> num;
if (num == 1) //code to execute if integer = 1
{
cout << "coffee selected" << endl;
}
else if (num == 2) //code to execute integer = 2
{
cout << "tea selected" << endl;
}
else if (num == 3) //code to execute if integer = 3
{
cout << "hot chocolate selected" << endl;
}
else if (num == 4) //code to execute if integer = 4
{
cout << "soft drink selected" << endl;
}
else if (num == 5) //code to execute if integer = 5
{
cout << "Exit Program" << endl;
control=0;
}
}
}
here is my ammended code this works. However i was unsure about initializing the num integer so i left it out but the code still executes and works correctly.