PDA

View Full Version : Urgent Help with C++



Dusk Eclipse
2011-11-22, 11:44 AM
I am sure there are some posters in the playground that are savy enough in C++ language to help me a bit.

For a project in school I need to develop a program in Dev C++ that functions as a menu between all the other projects I have already done, I am thinking on using the "Switch Case" command and it works; but I don't know how to make it able to return to the root menu.

So can anybody help me please?

Douglas
2011-11-22, 11:56 AM
Could you give a more detailed description of what you're trying to do? At this point I'd have to make several guesses before even trying to give useful advice. Seeing some of your code might help too.

pendell
2011-11-22, 11:58 AM
Douglas' response is mine as well. You say "menuing". Is this a Visual Studio Windows menu? A text menu? Something else?


Respectfully,

Brian P.

Dusk Eclipse
2011-11-22, 12:17 PM
Sorry for being so vague.

I need to do a text menu from which I can select functions (the other programs) run them and then after finishing return to the very first menu.

I haven't really starting coding this program; but I have a program that should work similarly



#include<stdio.h>
#include<conio.h>
main()
{
int Op;
float a,b,c;
clrscr();
printf("Introduce la operacion a realisar (1 Suma, 2 Resta, 3 Multiplicacion, 4 Divicion");
scanf("%d",&Op);

switch(Op)
{
case 1:
printf("Suma\Op");
clrsc();
printf("Introduce el primer sumando a");
scanf("%d",&a);
printf("Introduce el segundo sumando b");
scanf("%d",&b);
c=a+b;
printf("El resulado de la Suma es=%d, c");
break;
case 2:
printf("Resta\Op");
clrscr();
printf("Introduce el minuendo a");
scanf("%d",&a);
printf("Introduce el sustraendo b");
scanf("%d",&b);
c=a-b;
printf("El resultado de la Resta es =%d, c");
break;
case 3:
printf("Multiplicacion\Op");
clrscr();
printf("Introduce el factor a");
scanf("%d",&a);
printf("Introducer el factor b");
scanf("%d",&b);
c=a*b;
printf("El resultado de la multiplicacion es =%d, c");
break;
case 4:
printf("Division\Op");
clrscr();
printf("Introduce el dividendo a");
scanf("%d",&a);
printf("Introduce el Divisor b");
scanf("%d",&b);
if (b==0)
printf("No se puede dividir entre 0");
else
c=a/b;
printf("El resultado de la multiplicacion es=d, c");
break;

default:
printf("ERROR 404 comando no encontrado");

}

getch();
}

I hope this clears up things a little.

Seerow
2011-11-22, 12:28 PM
Couldn't you just put it in a loop? something like




do
{

*display all options*
*last option states "Choose 0 to exit"*

*insert case statement here*

}while(option!=0)



So it'll keep looping through asking them to enter which program they want to run, until they select 0, at which point setting option = 0 causes the loop to end and the program terminates.

Douglas
2011-11-22, 12:30 PM
So, you need your program to display a list of options, take a number as input, execute one of the options, and then go back to displaying the list and asking for a choice again, all with plain text on the console? And you've got everything except the "go back to main list" part?

I've got one word for you: loops.

In particular, a while or do...while loop is probably the best fit. Since this is a school assignment, I think I'll stop there as it should be enough to get you pointed in the right direction.

Dusk Eclipse
2011-11-22, 12:31 PM
I actually haven't thought a about that... I'll try it.

Edit: Thank you all, you were really helpful, I'll post my code once I finish it:smallsmile: