Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#include <stdio.h>

void main (void)  {
    int code, qty;
    float price, amt, totalAmt, cash, change;
    char addAnother;
    
    // do-while loop -> post-test
    // while loop -> pre-test
    // for loop -> pretest
    
 do {
    system("cls");
    printf("======================\n");
    printf("computer\n");
    printf("=======================\n\n");
    printf("[1] HP Pavilion\t\tphp 3,500.00\n");
    printf("[2] ChromeBook\t\tphp 2,500.00\n");
	printf("[3] Acer Aspire\t\tphp 4,500.00\n");
    printf("[4] HP Ram 16GB\t\tphp 500.00\n");
	printf("[5] chromeBook Ram 32GB\t\tphp 750.00\n");
	printf("[6] Acer Ram 64GB\t\tphp 1,500.00\n");
    
    printf("\nEnter Code\t: ");
    scanf("%d", &code);
    printf("nEnter Quantity\t:");
    scanf("%d", &qty);
    
    switch(code) {
        case 1: price = 3,500.00;
                break;
        case 2: price = 2,500.00;
                break;
	    case 3: price = 4,500.00;
		        break;
        case 4: price = 500.00;
                break;
		case 5: price = 750.00;
		        break;
		case 6: price = 1,500.00;
    }
    amt = price * qty;
    printf("\nAmount\t\t: %.2f", amt); 
    
    totalAmt = totalAmt + amt;
    printf("\nTotalAmount\t: %.2f", totalAmt);
    
    printf("\nAdd another oder(y/n)? ");
    addAnother = getchar();
    }while(addAnother == 'y' || addAnother == 'Y');
    
    do{
        printf("\nCash Tendered\t: ");
    scanf("%f", &cash);
    }while(cash < totalAmt);
        
    
    change = cash - totalAmt;
    printf("\nChange\t\t: &.2f", change);


What I have tried:

#include <stdio.h>

void main (void)  {
    int code, qty;
    float price, amt, totalAmt, cash, change;
    char addAnother;
    
    // do-while loop -> post-test
    // while loop -> pre-test
    // for loop -> pretest
    
 do {
    system("cls");
    printf("======================\n");
    printf("computer\n");
    printf("=======================\n\n");
    printf("[1] HP Pavilion\t\tphp 3,500.00\n");
    printf("[2] ChromeBook\t\tphp 2,500.00\n");
	printf("[3] Acer Aspire\t\tphp 4,500.00\n");
    printf("[4] HP Ram 16GB\t\tphp 500.00\n");
	printf("[5] chromeBook Ram 32GB\t\tphp 750.00\n");
	printf("[6] Acer Ram 64GB\t\tphp 1,500.00\n");
    
    printf("\nEnter Code\t: ");
    scanf("%d", &code);
    printf("nEnter Quantity\t:");
    scanf("%d", &qty);
    
    switch(code) {
        case 1: price = 3,500.00;
                break;
        case 2: price = 2,500.00;
                break;
	    case 3: price = 4,500.00;
		        break;
        case 4: price = 500.00;
                break;
		case 5: price = 750.00;
		        break;
		case 6: price = 1,500.00;
    }
    amt = price * qty;
    printf("\nAmount\t\t: %.2f", amt); 
    
    totalAmt = totalAmt + amt;
    printf("\nTotalAmount\t: %.2f", totalAmt);
    
    printf("\nAdd another oder(y/n)? ");
    addAnother = getchar();
    }while(addAnother == 'y' || addAnother == 'Y');
    
    do{
        printf("\nCash Tendered\t: ");
    scanf("%f", &cash);
    }while(cash < totalAmt);
        
    
    change = cash - totalAmt;
    printf("\nChange\t\t: &.2f", change);
Posted
Updated 26-Sep-22 5:27am
Comments
Kingsley Obi 26-Sep-22 10:12am    
I need help to create a store to keep track of computer with computer brand and model ram and ram size to display
1: Display the tota; and average price of all computer
2: display the brand of the most expensive computer

Variables data type
basic input/output
logic(if else if statements
loops( for, while, or do-while. hint: data has to be processed within the loop)
jeron1 26-Sep-22 10:14am    
You have not asked a question.

1 solution

While you have not actually asked a question, there are several issues with your code. Here are a few of them.
C++
case 6: price = 1,500.00;
price is a floating point value and floats can not have commas embedded in them. They must be written without the comma like this :
C++
case 6: price = 1500.00;
The previous five prices must also be written without commas.

I like to use toupper or tolower so I only have to check a character's value one time. That can look like this :
C++
    addAnother = getchar();
    addAnother = tolower( addAnother );
} while( addAnother == 'y' );
One other thing I noticed is the format specifier for one of your printf statements is incorrect. It should look like this :
C++
printf("\nChange\t\t: %.2f", change);
with a percent sign instead of an ampersand.
 
Share this answer
 
Comments
Kingsley Obi 26-Sep-22 17:55pm    
how to fix sh 1 cls not found in c programming

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900