[Solved] multiple items price calculation in C


You need a variable total to add up the total cost. Your code will look like this:

#include<stdio.h>

int main()

{
    char ch;

    int total=0;
    printf("Which option will you choose:\n");
    printf("a) cpu 1 \n");
    printf("b) cpu 2 \n");
    scanf("%c", &ch);

    switch (cpu)
    {
        case 'a':
                printf("The price is 110 \n");
                 total+=110;
                break;
        case 'b':

                printf("The price is 140\n");
                total+=140;
                break;

        default:
                printf("Invalid choice.Switching to next question\n");
                        }
    //ask next question.
    //get input
    //use a switch like the above one
    //add total
    //repeat this as many times you want

    printf("That'll cost %d",total);
    return 0;
}

3

solved multiple items price calculation in C