Skip to content

PRO TIP Block youtube.com at the DNS level โ€” Pi-hole, NextDNS or your hosts file โ€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Let’s code a shopping cart program with C programming ๐Ÿ›’

33.3K views on YouTube

#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;