Hallo ich bin neu in C und ich schrieb ein einfaches Programm. Ich möchte das Programm neu zu starten, wenn der Benutzer die falsche Wahl gepflückt, hier ist der Code:Wie kann ich das Programm in C neu starten?
#include <stdio.h>
#include <cs50.h>
int main(void){
char choices;
float math, pc, svt, eng, philo;
do {
do {
printf("Enter your math score: ");
math = GetFloat();
}
while(math>20 || math<0);
do {
printf("Enter your pc score: ");
pc = GetFloat();
}
while(pc>20 || pc<0);
do {
printf("Enter your svt score: ");
svt = GetFloat();
}
while(svt>20 || svt<0);
do {
printf("Enter your eng score: ");
eng = GetFloat();
}
while(eng>20 || eng<0);
do {
printf("Enter your philo score: ");
philo = GetFloat();
}
while(philo>20 || philo<0);
printf("Are you pc or sm?\n");
printf("Write 1 for pc. 2 for sm\n");
int choice = GetInt();
if(choice == 1){
float score = (math*7 + pc*7 + svt*7 + eng*2 + philo*2)/25;
printf("Your score is %.2f\n", score);
}
else if(choice == 2){
float score = (math*9 + pc*7 + svt*3+ eng*2 + philo*2)/23;
printf("Your score is %.2f\n", score);
}
else{
printf("You've picked the wrong choice \n");
}
printf("Do you want to try it again? (Y/N) ");
choices = getchar();
while (choices != '\n' && getchar() != '\n') {};
} while (choices == 'Y' || choices == 'y');
}
Also, was ich meine hier, ich möchte den Code in dem anderen Block einzufügen, um das Programm neu zu starten und den Benutzer geben einander mal. Es wäre sehr schön, wenn ich ihn einfach wieder zwischen 1 oder 2 wählen lassen würde.
Wenn Sie irgendwelche Vorschläge oder Verbesserungen haben, zögern Sie bitte nicht zu kommentieren. Thanks :)
http://www.tutorialspoint.com/cprogramming/c_goto_statement.htm –
* „wollen das Programm neu zu starten, wenn der Benutzer die falsche Wahl gepflückt“ * Nein, Sie nicht. Sie möchten den Benutzer für eine bessere Eingabe erneut auffordern. –
@AlexandruCimpanu 'goto', wirklich? http://stackoverflow.com/questions/46586/goto-still-consided-harmful – Jezor