not long started c++ and i am looking at getting the user to enter the task they want to do, then the program asks is they have another task, and loops until the user replies no or 2.
the problem i am having is getting the program to loop back to the cin>>task part
#include <iostream>
int database = 0;
int spreadsheet= 0;
int word = 0;
int ppt = 0;
int img = 0;
int cont;
usingnamespace std;
int main()
{
int task;
cout<<"what task would you like to perform?"<<endl;
cout<<" 1 = Open a database"<<endl;
cout<<" 2 = Open a Spreadsheet"<<endl;
cout<<" 3 = Open a Word Document"<<endl;
cout<<" 4 = Open a Presentation"<<endl;
cout<<" 5 = Open an Image"<<endl;
cout<<"continue? 1 = yes 2 = exit"<<endl;
cin>>cont;
cout<<"please eneter which task you want to perform"<<endl;
cin>>task;
cout<<"---------------------------------------------------------------"<<endl;
if (cont == 1)
switch(task)
{
case 1:
cout<<"you have opened a database, enjoy"<<endl;
database ++;
cout<<"you have opened "<<database<<" databases today"<<endl;
cout<<"continue? 1 = yes 2 = exit"<<endl;
cin>>cont;
//CASE 2
case 2:
cout<<"you have opened a spreadsheet, enjoy"<<endl;
spreadsheet ++;
cout<<"you have opened "<<spreadsheet<<" spreadsheets today"<<endl;
cout<<"continue? 1 = yes 2 = exit"<<endl;
cin>>cont;
break;
case 3:
cout<<"you have opened a Word Document"<<endl;
word ++;
cout<<"you have opened "<<word<< " word documents today"<<endl;
cout<<"continue? 1 = yes 2 = exit"<<endl;
cin>>cont;
break;
case 4:
cout<<"you have opened a Powerpoint Presentation"<<endl;
ppt++;
cout<<"you have opened "<<ppt<<" presentations today"<<endl;
cout<<"continue? 1 = yes 2 = exit"<<endl;
cin>>cont;
break;
case 5:
cout<<"you have opened an image"<<endl;
img++;
cout<<"you have opened "<<img<<" images today"<<endl;
cout<<"continue? 1 = yes 2 = exit"<<endl;
cin>>cont;
}}
Try a while loop that goes on as long as your cont variable isn't 2 (your exit code).
1 2 3 4
while(cont != 2)
{
//Get task and do switch
}
Then you move your code for getting the task into the loop, also put the switch in the loop, so you keep on asking for tasks and preforming that task for as long as the user didn't enter 2.
Your complete code would then be something like this: