Merge branch 'master' of github.com:jackbenny/learning_c

This commit is contained in:
Jack-Benny Persson 2015-10-17 20:25:44 +02:00
commit c0efe9db77
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#include <stdio.h>
/* Write a program that gives a customer 10% off the total price when he shops
* for at least 1000 SEK. Assume for simplicity that he only shops one kind of
* product.
*/
int main()
{
float discount = 10;
int limit = 1000;
int items;
float subtotal, total, price;
printf("Number of items: "); scanf("%d", &items);
printf("Price per unit: "); scanf("%f", &price);
subtotal = price * items;
if (subtotal >= limit)
{
total = subtotal*((100-discount)/100);
}
else
{
total = subtotal;
}
printf("Total price: %.2f\n", total);
return 0;
}

View File

@ -0,0 +1,31 @@
#include <stdio.h>
#define DISCOUNT 10.0
#define LIMIT 1000
/* Write a program that gives a customer 10% off the total price when he shops
* for at least 1000 SEK. Assume for simplicity that he only shops one kind of
* product.
*/
int main()
{
int items;
float subtotal, total, price;
printf("Number of items: "); scanf("%d", &items);
printf("Price per unit: "); scanf("%f", &price);
subtotal = price * items;
if (subtotal >= LIMIT)
{
total = subtotal*((100-DISCOUNT)/100);
}
else
{
total = subtotal;
}
printf("Total price: %.2f\n", total);
return 0;
}