Back to menu with a character instead of an integer

Viewed 31

When you first start the program you get a "menu" where you can choose to enter integers by clicking on the keyboard e. You can enter up to 10 integers. If you only want to enter 3 integers you can go back by clicking on 0.

For example if I enter 12 45 5 and then 0, I go back to "View(v)Enter(e):". It works great, but now instead of 0 I want to go back to the menu with a character, for example character q. Since the whole program is over 100 lines I'm only gonna post the function enter and main(). Since I just copied a part of the program please ignore if the curly brackets are wrong, I just need the help with enter function.

    int main()
    {
    
        int measurements[10];
        int nrOfMeasurements = 0;
        char ch;
    
        while (1)
        {
            printf("View(v)Enter(e):");
            scanf(" %c", &ch);
            switch (ch)
            {
    
            case 'e':
                enter(measurements, &nrOfMeasurements);
                    break;
         }
      }return 0;
  }

    void enter(int a[], int *n)
    {
        while (*n < 10){
            printf("Enter measurement #%d(q to Quit)", *n + 1);
            scanf("%d", &a[*n]);
            if (a[*n] > 0){
                (*n)++;
            }
            else{
                break; 
            }
        }
    }
0 Answers
Related