Member Avatar for Raim

Basically, I made a small calculator. It does the PEMDAS and factorials. Part of my code is here:

#include "stdafx.h"
#include "iostream"
#include "stdio.h"
#include "math.h"
using namespace std;
short MENU (void);
void raiz (void);
void suma (void);
etc.....
int main ()
{
	short OPC;
	OPC=MENU ();
	do
	{
		switch (OPC)
		{
		case 1: raiz();
			break;
		case 2: suma();
			break;
		etc.....
		case 8: break;
		default: cout<<"\n Seleccion Erronea. \n ";
			
			OPC=MENU();
		}
	}
	while ((OPC>8) || (OPC<1));
	
	cout<<"\n\n\t\t ";
	system  ("pause");
	return 0;
}

After that, are the modules themselves (short MENU, void suma, etc) which do each process. Nevertheless, I want that if I selected the suma (Addition) and finished with it, the program would send me back to the menu and keep on going until I select case 8 (Quit).
Help?

Where does your loop actually start?
Where do you want the loop to start?

Member Avatar for Raim

So I just showed you my libraries and the main part. There's a menu later on:

short MENU (void)
{
	short RES;
	cout<<"\n\t  **********CALCULADORA********* \n ";
	cout<<"Seleccione su operacion. \n ";
	cout<<"1. Raiz cuadrada \n ";
	cout<<"2. Suma \n ";	
	cout<<"3. Resta \n ";
	cout<<"4. Multiplicacion \n ";
	cout<<"5. Division \n ";
	cout<<"6. Exponentes \n ";
	cout<<"7. Factorial \n ";
	cout<<"8. Salir. \n ";
	cin>>RES;
	system ("cls");
	cout<<endl;
	return RES;

And from the int main it sends me to any of the modules. Ex:

void factorial (void)
{	int VA;
	int FACT=1;
	cout<<"Ingrese factorial : ";
	cin>>VA;
	for (int CONT=1;CONT<=VA;CONT++)
	{
		FACT*=CONT;
		
	}
		cout<<"\n\n La respuesta es : "<<FACT <<endl;
		return;
}

That's the factorial module, but after it finishes doing its own process, I want the loop to go back to the menu and do some other process from my modules, say, division:

void division (void)
{
	double N1,N2,RE;
	cout<<"\n Ingrese el primer numero : ";
	cin>>N1;
	cout<<"\n Ingrese el segundo numero : ";
	cin>>N2;
	RE=N1/N2;
	cout<<"\n Su respuesta es: "<<RE <<"\n ";
	return;
}

All in all, there are seven modules, not counting the menu itself.
Long story short, after a process is done, I want the menu to start over and send me to another process I wish to make.

Look at your first post. Answer my questions. Post the answer.

Your second post adds nothing to the question -- the answer is already in the first post.

@OP:

int userInput = 0;
const int QUIT = 8;
do{
  cin >> userInput;
  switch(userInput){ 
     case ADD: doAdd(); break;
     case SUB: doSub(); break;
     case MULT: doMult(); break;
     case DIV: doMult(); break;
     case FACT: doFact(); break;
     case QUIT: break;
     default: doErrorInput(); break;
  }
 if(userInput != QUIT){ showMenu(); }

}while(userInput != QUIT);
commented: Thank you for making my post a waste. -4
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.