我使用什么代码询问数量和付款方式?

问题描述 投票:-2回答:1

我认为问题在嵌套if开关之前开始,因为它应在代码末尾输出sales = quantity * pricechange = payment - total amount的结果并询问quantityPayment

#include<stdio.h>
main() {
int choice,ch,Quantity,Payment;
printf(" SELECT 1 OPPO \n SELECT 2 SAMSUNG \n SELECT 3 HUAWEI \n\n\n CHOICE: ");
scanf("%d",&choice);
switch(choice){
  case 1:
        printf("\n OPPO!!!"); 
        printf("\n\nSelect 1 oppo F11 \n Select 2 OPPO A5S \n select 3 OPPO F9 PRO \n\n CHOICE: "); 
        scanf("%d",&ch);
        switch(ch){
                   case 1:
                      printf("\n Oppo F11 smartphone was launched in March 2019. The phone comes with a 6.50-inch touchscreen display.\n");
                      printf("\n P 18,990.00");
                      break;             
                   case 2:
                      printf("\n Oppo A5s is built quite sturdily and feels light in hand considering its large footprint.\n");  
                      printf("\n P 6,990.00");
                      break;
                   case 3:
                      printf("\n Oppo F9 Pro features a dual rear camera setup.\n");
                      printf("\n P 15,990.00");
                      break;
        }
        break;

   case 2:
        printf("\n SAMSUNG!!!");
        printf("\n\nSelect 1 SAMSUNG  GALAXY A10\n Select 2  SAMSUNG NOTE 10\n select 3 SAMSUNG S9\n\nCHOICE: ");               
        scanf("%d",&ch);
        switch(ch){
                   case 1:
                      printf("\n SAMSUNG Galaxy  A10 is not a light smartphone, but it is also rather large, making its heft appropriate at least.\n");
                      printf("\n P 6,990.00");
                      break;             
                   case 2:
                      printf("\n The Galaxy Note 10 is Samsung’s easiest to use S Pen-toting phone yet, and while there may not be any game-changing features to make this a must-buy handset, it’s a solid addition to the Note range.\n");  
                      printf("\n P  53,990.00");
                      break;
                   case 3:
                      printf("\n The Samsung Galaxy S9 features a 12MP rear camera with dual-aperture technology. This is the big takeaway from the S9.\n");
                     printf("\n P 45,990.00"); 
                      break;
         }       
        break;
   case 3:
        printf("\nHUAWEI!!!"); 
        printf("\n\nSelect 1 HUAWEI P30 \n Select 2 HUAWEI NOVA 5T \n select 3 HUAWEI NOVA 3I\n\n CHOICE: "); 
        scanf("%d",&ch);
        switch(ch){
                   case 1:
                      printf("\n The Huawei P30 has one of the best cameras we've seen in a phone, with features like incredible optical zoom and night mode that other handsets could only dream of, but other than that it feels more like a decent mid-range handset than a flagship.\n");
                      printf("\n P 50,990.00");
                      break;             
                   case 2:
                      printf("\n Hiding the front camera beneath the screen, HUAWEI nova 5T’s screen retains its full integrity, revolutionizing user experience.\n");  
                      printf("\n P 14,990.00");
                      break;
                   case 3:
                      printf(" \n HUAWEI nova 3i provides three color models for you to choose from, Pearl White, Black and Iris Purple. With beautiful hues of color on the back glass and metal mid-frame, you will enjoy wonderful visual and handling experience.\n");
                      printf("\n P 14,990.00");
                      break;
         }       
        break;

   default:
        printf("\n TRY AGAIN CHOOSE YOUR PHONE BRAND WISELY!!!");                       
}                   
     scanf("%d", &quantity);
     total Amount = quantity * price;
     scanf("%d", &payment);
     scanf("change = Payment - total Amount);

getch();
}
c switch-statement printf stdio nested-if
1个回答
0
投票
您应该定义另一个变量来指示所选电话的价格,例如phonePrice。在您的嵌套开关中,分配该phonePrice。然后,您可以使用该价格变量来计算金额和所有其他内容。
© www.soinside.com 2019 - 2024. All rights reserved.