steve_rm
Oct 24th, 2002, 09:10 PM
Hello
The program will ask the user to select from the menu options, then call that function.
Can you tell me is there a better way to write this switch statement. My programming does not work well, and l am wondering is there a better way to write this type of program.
One more quick question, what is the keyword that allows you to clear the screen, so when a menu option is selected it will display a new screen.
My code is below
Thanks in advance
#include "stdio.h"
#include "ctype.h"
#include "conio.h"
//Function prototypes
void Divide(void);
void Multiply(void);
void Subtrack(void);
void Add(void);
void main(void)
{
int MenuOption = 0;
char Exit = NULL;
printf("Welcome to Mr Calculator");
printf("\n[1] Add");
printf("\n[2] Subtract numbers");
printf("\n[3] Divide numbers");
printf("\n[4] Multiply numbers");
printf("\n[5] Exit from program");
do{
printf("\nPlease choose a option from the menu: ");
scanf("%d",&MenuOption);
switch(MenuOption)
{
case(1):
//Function to add
break;
case(2):
//Function to subtract
break;
case(3):
//Function to divide
break;
case(4):
//Function to multiply
break;
case(5):
printf("Are you sure you want to exit this program (y/n): ");
Exit = getchar();
Exit = toupper(Exit);
default:
printf("Invalid - input, please re-enter");
}
}while(MenuOption != 'Y');
}
void Add(void)
{
//Code to go here
}
void Subtract(void)
{
//Code to go here
}
void Multiply(void )
{
//Code to go here
}
void divide(void )
{
//Code to go here
}
The program will ask the user to select from the menu options, then call that function.
Can you tell me is there a better way to write this switch statement. My programming does not work well, and l am wondering is there a better way to write this type of program.
One more quick question, what is the keyword that allows you to clear the screen, so when a menu option is selected it will display a new screen.
My code is below
Thanks in advance
#include "stdio.h"
#include "ctype.h"
#include "conio.h"
//Function prototypes
void Divide(void);
void Multiply(void);
void Subtrack(void);
void Add(void);
void main(void)
{
int MenuOption = 0;
char Exit = NULL;
printf("Welcome to Mr Calculator");
printf("\n[1] Add");
printf("\n[2] Subtract numbers");
printf("\n[3] Divide numbers");
printf("\n[4] Multiply numbers");
printf("\n[5] Exit from program");
do{
printf("\nPlease choose a option from the menu: ");
scanf("%d",&MenuOption);
switch(MenuOption)
{
case(1):
//Function to add
break;
case(2):
//Function to subtract
break;
case(3):
//Function to divide
break;
case(4):
//Function to multiply
break;
case(5):
printf("Are you sure you want to exit this program (y/n): ");
Exit = getchar();
Exit = toupper(Exit);
default:
printf("Invalid - input, please re-enter");
}
}while(MenuOption != 'Y');
}
void Add(void)
{
//Code to go here
}
void Subtract(void)
{
//Code to go here
}
void Multiply(void )
{
//Code to go here
}
void divide(void )
{
//Code to go here
}