vendredi 29 mai 2020

How to jump back to the top of the code after if statement C language

I'm trying to make my program to start again from the beginning after user has selected an option from a menu. When the user selects 1 and then enters the amount of the donation I want the program to start again and show the menu What would you like to do? and not to just restart just the if statement.

Should I add a for loop inside of the if statement to accomplish this? thanks for the help.

 printf("What would you like to do?\n");
    printf("      1 - Donate\n");
    printf("      2 - Invest\n");
    printf("      3 - Print balance\n");
    printf("      4 - Exit\n");
    printf("\n");

    //scans menu choice
    scanf("%d", &menu_option);

    if(menu_option==1)
    {
    printf("How much do you want to donate?\n");
    scanf("%lf", &donation);
    donations_made++;
    current_Balance = initial_Balance + donation;
    }

Aucun commentaire:

Enregistrer un commentaire