how can i return cases 1,2,3 and default in to the main function? when i press 1 as key to return to the main function.. the prompt will appear "press any key to continue"

how can i return it to the main menu?

#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
int x,a,b,c,d,e,f,y;
	int average= 0;
	double total=0;
	double count=0;
	cout<<"Menu"<<'\n'<<'\n';
    
	cout<<"[1]"<<" "<<"Average Program"<<'\n'<<'\n';
    
	cout<<"[2]"<<" "<<"The Author"<<'\n'<<'\n';
	
	cout<<"[3]"<<" "<<"Exit?"<<'\n'<<'\n';

	cin>>x;

	switch (x){

	case 1 :
		
		cout << "Enter how many values you want to add: "; 
       cin >> y; 
   
   
    for (a = 1; a <= y; a++) 
    { 
        cout << "Input" << x++ << " = "; 
        cin >> b; 
        total += b;        
   count = count + 1;
	} 
					average = total/count;
					cout<<"The Average is:"<<" "<<average<<'\t';
				
			

				cout<<"Go back to main?"<<" "<< "1 to go back 0 to terminate the function"<<'\n';
					cin>>c;
				if (c==1){
					return 1;
				}
			
	break;
	case 2 : 
		cout<<"Name:"<<" "<< "Exekiel Vergara"<<'\n';
		cout<<"Date created:"<<" "<< "Jan 10 2010"<<'\n';
		cout<<"Program Description:"<<" "<< "This program will print the 3 functions, the average program, the author and the exit menu."<<'\n'<< "I used Switch statements in order to choose the program the user want.The average program "<<'\n';  	
		 cout<<"Go back to main?"<<" "<< "1 to go back 0 to terminate the function"<<'\t';
					cin>>d;
			
				
					if (d==1){
						
					}
					
				if (d==0){
					break;
				
				}
	
	case 3 :
		cout<<"Exit?"<<" "<<"1 to go back 0 to terminate the program"<<'\n';
		cin>> e;
	
		if (e==0){
			cout<<"Terminating the program in 3...2...1..."<<"\n";
			exit (EXIT_SUCCESS);
		}
		else if (e==1)
			exit (EXIT_FAILURE);
		break;

	default: 

		cout<<"Wrong Input"<<" "<<"Try another[1/0]"<<'\n'<<"1 to go to main"<<" "<<"0 to exit the program"<<'\n';
      
		cin>>f;
		if (f==0){
			cout<<"Terminating the program in 3...2...1..."<<"\n";
		exit (EXIT_SUCCESS);
		}
		break;

		}
			return 0 ;
	
		}

thank you..

Recommended Answers

All 2 Replies

I can't even follow your code with the formatting you have. Please re-format and post again.

between lines #8 & 9 insert do{

at line #90 put }while(x != 3);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.