I'm not quite sure on what I'm doing wrong, it runs but just keeps displaying the displayMenu with any number and once I choose any number larger than 4 its displays my favorite food. This is my very first coding class ever so if anyone can dumb down the explanation it would be very helpful
Here is the assignment
Use a do/while statement to display a menu.
- loop in main function
- calls displayMenu function to display menu
- based on the choice entered call the corresponding function
- 1 to display your name
- 2 to display your favorite color
- 3 to display your favorite food
- exit the loop when user enters ANY number except 1 through 3 ( complex condition)
- displayMenu
- take no arguments, returns integer (choice selected by the user)
- menu options
- 1 name
- 2 favorite color
- 3 favorite food
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int displayMenu(int answer);
void displayName();
void displayColor();
void displayFood();
int main(void)
{
unsigned int counter = 0;
int option = 0;
int num = 0;
do
{
option = displayMenu(num);
}
while (option <= 3)
{
if (option == 1)
{
displayName();
}
else if (option == 2)
{
displayColor();
}
else if (option = 3)
{
displayFood();
}
else
{
printf("\n");
}
}
}
int displayMenu(int answer)
{
int choice;
puts("Choose a number to display:");
printf("%s", "1-display name, 2-to dsiplay favorite color, 3-
display favorite food, any other number to quit:");
scanf("%d", &choice);
return choice;
}
void displayName()
{
puts("Tiffany");
}
void displayColor()
{
puts("Red");
}
void displayFood()
{
puts("Anything Japanese");
}