-1

I think the problem starts before the nested if switch because at the end of the code it should output the result of sales = quantity * price and change = payment - total amount and asking quantity and 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();
}
laura
  • 19
  • 5
  • C and C++ are (albeit sharing quite some commonalities) entirely different languages, so you opt for one. Your code seems to be pure C, so I dropped C++ for you. – Aconcagua Oct 13 '19 at 10:07
  • First of all, please learn the difference between C and C++. They are two very different programming languages, and you should very seldom need to use both tags for your questions. Secondly, welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Oct 13 '19 at 10:07
  • When you post code, it should be the code you actually use. The code you have posted won't compile - in either C or C++, as there are some major errors in the last 5 or 6 lines of code - mostly simple typing errors (quantity in place of Quantity). But what is "total Amount" and what is "price?" – Adrian Mole Oct 13 '19 at 10:11
  • If I recall correctly, C99 removed implicit int as return type. In any case, it is bad practice to omit the return type, so it should be: `int main(void);` – Aconcagua Oct 13 '19 at 10:16
  • You might just store the price immediately when user selects a phone: `int price; switch(...) { switch(...) { case X: printf(...); price = 77; break; } }`. Then you can use it afterwards. – Aconcagua Oct 13 '19 at 10:19
  • `total Amount =` declares a variable named `Amount` of type `total` – but that type isn't defined *anywhere*. Be aware that a space is a token separator and cannot ever be part of an identifier, be it for a variable, function or struct. If you want to separate, you can use underscore (`_`) instead (but there are some rules for, such as two subsequent underscores or initial underscore followed by capital letter being reserved). So you'd have `int total_amount = ...`. – Aconcagua Oct 13 '19 at 10:23
  • General advice: It is not the task of a console application to keep the console window open, so better don't get used to bad practices like `getch()`, `system("pause")` and alike; they only make your programme unusable in batch scripts. Better: open a console manually and start your programme from within. – Aconcagua Oct 13 '19 at 10:28

1 Answers1

0

You should define another variable to indicate the price of your selected phone, say phonePrice. In your nested switch, assign that phonePrice. Then you can use that price variable to calculate the amount and all other things.

By the way, use a printf to prompt the user to enter the quantity before the scanf. Don’t just simply use scanf without prompting the user what to do.