Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver2
70いいね 2506回再生

⭐ Let's code a shopping cart program 🛒

#coding #programming #cprogramming

This is a beginner's practice project to help you get accustomed to accepting user input in C.

// SHOPPING CART PROGRAM

char item[50] = "";
float price = 0.0f;
int quantity = 0;
char currency = '$';
float total = 0.0f;

printf("What item would you like to buy?: ");
fgets(item, sizeof(item), stdin);
item[strlen(item) - 1] = '\0';

printf("What is the price for each?: ");
scanf("%f", &price);

printf("How many would you like?: ");
scanf("%d", &quantity);

total = price * quantity;

printf("\nYou have bought %d %s/s\n", quantity, item);
printf("The total is: %c%.2f", currency, total);

return 0;

コメント