какой код я использую, чтобы узнать количество и оплату? - PullRequest
0 голосов
/ 13 октября 2019

Я думаю, что проблема начинается перед вложенным переключателем if, потому что в конце кода он должен вывести результат sales = quantity * price и change = payment - total amount и запросить quantity и Payment

#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();
}

1 Ответ

0 голосов
/ 14 октября 2019

Вы должны определить другую переменную, чтобы указать цену выбранного телефона, например phonePrice. В своем вложенном переключателе назначьте этот phonePrice. Затем вы можете использовать эту ценовую переменную для расчета суммы и всех других вещей.

Кстати, используйте printf, чтобы предложить пользователю ввести количество до сканирования. Не просто используйте scanf, не подсказывая пользователю, что делать.

...