查看: 2035|回复: 3
|
急!C program stpm ict
[复制链接]
|
|
大家好,我是stpm ict学生
这次我遇到难题了,就是要写 如图 的 c program
how many kids 开始
我就不懂怎么写了,因为我写到很长,老师不要,因为她说很乱
第一个孩子没有discount,两个开始就有discount total price 10%,请问各位会写 c 的大大,可以给点tips?
我 B1 的 code 是
#include <stdio.h>
int main()
{
printf("Welcome to Sayang Pintar Kindergarten and Nursery\n");
printf("-------------------------------------------------\n\n");
printf("Packages offered are as follows:\n\n");
printf("Package 1: Kindergarten(8.30 a.m. - 12.30 p.m.)\nMonthly fee for package 1: RM170.00\n\n");
printf("Package 2: Kindergarten and Nursery(7.00 a.m. - 3.00 p.m.)\nMonthly fee for package 1: RM320.00\n\n");
printf("Package 3: Kindergarten and extended Nursery(7.00 a.m. - 6.00 p.m.)\nMonthly fee for package 1: RM440.00\n\n");
int choice;
printf("Please choose your package: 1, 2 or 3: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\n** Your monthly fee : RM170.00 **\n\n");
break;
case 2:
printf("\n** Your monthly fee : RM320.00 **\n\n");
break;
case 3:
printf("\n** Your monthly fee : RM440.00 **\n\n");
break;
default:
printf("\n** Invalid package **\n\n");
}
printf("Thank you!!\n");
return 0;
}
急啊,我想了两天都不会,明天要交了
|
-
题目
|
|
|
|
|
|
|
发表于 9-2-2014 08:08 PM
|
显示全部楼层
- sum = 0;
- for(i=0; i<num_of_kids; i++)
- {
- ///get pakage choice
- ...
- sum += pakage_price;
- }
- if(num_of_kids > 1)
- {
- total = sum - 10%;
- }
复制代码 |
|
|
|
|
|
|
|
发表于 9-2-2014 08:13 PM
|
显示全部楼层
我不是 C programmer,
但是我可以分享我的 logic,
你get了user input (how many kid)
放进 for loop 然后让 user key in package,
我会把 package 1,2,3 放进不同的 variable,
package 1 = 170
package 2 = 320
package 3 = 440
然后 count 有多少个 package 1,2,3
再加起来...
过后再放个 if else,
if user input (how many kid) >1,
total 除 10 然后乘 9 |
|
|
|
|
|
|
|
楼主 |
发表于 9-2-2014 08:45 PM
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|