- Joined
- May 1, 2023
- Messages
- 7
- Reaction score
- 1
Hello All,
am stuck using a recursive menu selection. It keeps iterating and do not know what I am missing from my code. Can anybody help.
I have tried putting the function inside the switch statements and it also is not getting me the results.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
void getTriangle();
void getRectangle();
void getSquare();
char displayMenu();
int main(void)
{
char input;
//display program
input = displayMenu();
//display shape + decision
do {
switch (input)
{
case 'A':
getSquare();
break;
case 'B':
getTriangle();
break;
case 'C':
getRectangle();
break;
case 'D':
default:
printf("Terminate Program!\n");
break;
}
} while (input != 'D');
return (0);
}
char displayMenu()
{
char userInput;
printf("A. Square\n");
printf("B. Triangle\n");
printf("C. Rectangle\n");
printf("D. Exit\n");
printf("Enter your selection: ");
scanf("%c", &userInput);
return toupper(userInput);
}
void getTriangle()
{
printf(" /\\ \n");
printf(" / \\ \n");
printf(" / \\ \n");
}
void getRectangle()
{
printf(" ************\n");
printf(" * *\n");
printf(" * *\n");
printf(" ************\n\n");
}
void getSquare()
{
printf(" *********\n");
printf(" * *\n");
printf(" * *\n");
printf(" *********\n\n");
}
am stuck using a recursive menu selection. It keeps iterating and do not know what I am missing from my code. Can anybody help.
I have tried putting the function inside the switch statements and it also is not getting me the results.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <ctype.h>
void getTriangle();
void getRectangle();
void getSquare();
char displayMenu();
int main(void)
{
char input;
//display program
input = displayMenu();
//display shape + decision
do {
switch (input)
{
case 'A':
getSquare();
break;
case 'B':
getTriangle();
break;
case 'C':
getRectangle();
break;
case 'D':
default:
printf("Terminate Program!\n");
break;
}
} while (input != 'D');
return (0);
}
char displayMenu()
{
char userInput;
printf("A. Square\n");
printf("B. Triangle\n");
printf("C. Rectangle\n");
printf("D. Exit\n");
printf("Enter your selection: ");
scanf("%c", &userInput);
return toupper(userInput);
}
void getTriangle()
{
printf(" /\\ \n");
printf(" / \\ \n");
printf(" / \\ \n");
}
void getRectangle()
{
printf(" ************\n");
printf(" * *\n");
printf(" * *\n");
printf(" ************\n\n");
}
void getSquare()
{
printf(" *********\n");
printf(" * *\n");
printf(" * *\n");
printf(" *********\n\n");
}