lundi 14 décembre 2015

what is better than if-statement when making a calculator

I'm trying to create a program that calculates the price of the selected food while displaying the total price. I can already calculate and display the total price. My problem is whenever the user enters "[3] exit" and he chooses "[1] reset", the program breaks and detects many error. I wonder what better statement should I use with my program. Thanks!

  void PriceCalculator(){

  printf("[1] spinach");
  printf("[2] romaine lettuce");
  printf("[3] exit");

  if(choice == 1){
        ...      
  }

  if(choice == 2){
        ...
  }

  if(choice == 3{
        printf("[1] reset");
        printf("[2] exit");

              if(choice == 1){
                    reset variables to 0;
              }else{
                    exit function go back to int main();
              }
  }

  }

Aucun commentaire:

Enregistrer un commentaire