SOAL DARI MODUL "C PROGRAMMING PROGRAM EXAMPLES"
MyJava Café wants you to write a program to take orders from the Internet. Your program asks for
the item, its price, and if overnight shipping is wanted. Regular shipping for items under $10 is
$2.00; for items $10 or more shipping is $3.00. For overnight delivery add $5.00. For example, the
output might be:
Enter the item:
Tuna Salad
Enter the price:
450
Overnight delivery (0==no, 1==yes):
1
Invoice:
Tuna Salad 4.50
shipping 7.00
total 11.50
SOLUTION
//menghitung harga antaran dengan syarat tertentu
#include <stdio.h>
#include <conio.h>
main()
{
float price, shipping, total;
int overnight_delivery;
char item[20] = " ";
printf("enter the item : \n");
scanf("%s", &item);
printf("enter the price : \n");
scanf("%f", &price);
printf("overnight delivery (0 = no, 1 = yes)\n");
scanf("%d", &overnight_delivery);
if(overnight_delivery == 1)
{
if(price < 10)
{shipping = 2.00 + 5.00;
}else
{shipping = 3.00 + 5.00;
}
}
if(overnight_delivery == 0)
{
if(price < 10)
{shipping = 2.00;
}else
{ shipping = 3.00;
}
}
printf("invoice : \n");
printf("%c %.2f", item, price);
printf(" \nshipping : %.2f\n", shipping);
printf("total : %.2f\n", price + shipping);
getch();
return 0;
}