Hello, I'm trying to return to the start by using "goto start:"
but everytime it goes to the start it prints the menu twice.
First run of the program is fine, I go to selection 'a' and when it finishes executing, "goto start:" goes to start, but then prints the menu twice. any idea whats going on?
Code:
#include <stdio.h>
#include <math.h>
main() {
start:;
char selection, a, b, c;
printf("Math Practice\n\n");
printf("a. Multiplication\n");
printf("b. Division\n");
printf("c. Exit\n\n");
printf("Select a,b or c\n");
printf("Selection ---> ");
scanf("%c", &selection);
fflush(stdin);
//selection A
if(selection == 'a') {
float firstNum, secNum, correct, total;
printf("Please enter your first number ---> ");
scanf("%f", &firstNum);
printf("\nPLease enter your second number ---> ");
scanf("%f", &secNum);
printf("\nEnter the correct answer to the first and second number ---> ");
scanf("%f", &correct);
total=firstNum*secNum;
if(correct == total) {
printf("\ncorrect!\n\n");
} else {
printf("wrong! the correct answer is %.0f\n\n", total);
}
goto start;
}
//selection b
else if(selection == 'b') {
printf("sdkbfhewhjbfdsjbhfsjb");
goto start;
}
//selection c
else if(selection == 'c') {
printf("goodbye :)");
}
else {
printf("Choose a proper selection.\n\n");
goto start;
}
}
Ive noticed that on the first print of the menu it says "choose a proper selection" what's up with this? because that's what's making it print twice.