0

So, I just started learning C, and I made this very simple program. It's basically a simple pizza app, where you enter the number of pizzas and confirm with Y/N. The problem comes When I enter the number of pizzas, but then the confirmation doesn't show up and the error message I made is printed, I actually found out that when I type 2Y the program run fine, the question is can i enter the number of pizzas and the confirmation response at an ordered manner, I mean no in the same time

Here's the code:

#include <stdbool.h>

 int main(void)
{
 int pizza;
 char ans;
 printf("Place the number of pizzas you want: ");
 scanf("%d", &pizza);
 if (pizza <= 3) {
   printf("You ordered %d pizzas\n", pizza);
   printf("Are you sure you want to order %d pizzas[Y,N]\n", pizza);
   scanf("%c", &ans);
   if (ans == 'Y') {
     printf("Thanks for ordering!\n");
     printf("Order will arrive in less than 30mins.");
   } else if(ans == 'N') {
     printf("No problem, thanks for your time!");
   } else {
     printf("Please make sure to choose either Y/N");
   };
 } else if(pizza <= 20) {
   printf("You ordered %d pizzas\n", pizza);
   printf("Are you sure you want to order %d pizzas[Y,N]\n", pizza);
   scanf("%c", &ans);
   if (ans == 'Y') {
     printf("Thanks for ordering!\n");
     printf("Order will arrive in probably more than an hour.");
   } else if(ans == 'N') {
     printf("No problem, thanks for your time!");
   } else {
     printf("Please make sure to choose either Y/N");
   };
   
 } else {
   printf("Sorry we can't provide your order, try a smaller number of pizzas, or either enter a valid positive number");
 }
 
 
 
 return 0;
}```
Bloctagon
  • 11
  • 4

0 Answers0