i am studying c on my own because i need it for my senior project and i also want to know it for my own.
Objective: Make menu with 10 options. Option 0 takes u to a silly "prelab" sub function and option 7 (will make it q later but for now 7 is good, will make the program quit)
Problem: I can make the program quit with the option 7 and make the program go to the prelab with option 0 but i can not make it go back to the main menu. Ive tried implementing another loop and many other things but can seem to figure it out, any help will be apreciated it. Thank you.
The program doesnt wait for the user to input a choice YES OR NO like I wanted to; in the desicionTime()
Code:
// TheMenu.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
void desicionTime (void);
int main()
{
for(;;)
{
char input;
int choice;
printf("\n\n 0. PreLab\n");
printf(" 1. The Menu\n");
printf(" 2. Switch Case\n");
printf(" 3. Random\n");
printf(" 4. Conversion\n");
printf(" 5. Game of Chance\n");
printf(" 6. Function Gnenerator\n");
printf(" 7. Attributes Menu\n");
printf(" 8. Resistor Color Code\n");
printf(" 9. Regression Line Crap\n");
printf(" q. Press q to quit: \n\n");
printf(" Choose an option and press enter please:");
scanf("%d",&choice);
if (choice==7)
{
break;
}
if (choice==0)
{
system("cls");
desicionTime();
}
}
return (0);
}
// desicionTime.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
desicionTime(void)
{
int age;
char input;
int loop;
for (;;)
{
printf("hey yo, what is your age? ");
scanf("%d",&age);
if (age<=25)
{
printf("\n\nyou are a young buck\n\n");
printf("\n\nagain?(y/n)");
input=getchar();
if (input=='n')
{
break;
}
if (input=='y')
{
desicionTime();
}
return(0)
}
else if (age>45)
{
printf("\n\nyou are an old fart\n\n");
}
else
{
printf("\n\nyou aiight\n\n");
}
}
return(0);
}
I dont want to use switch case for now, only if that is the only option left. But there are probably many other ways to do it.