70,005
社区成员




#include "stdio.h"
#include "stdlib.h"
#include "math.h"
double teacher_total(double _amount)
{
double total;
printf("Total purchases $%6.2lf\n", _amount);
if(_amount >= 100)
{
total = _amount * (1 - 0.12);
printf("Teacher's discount (12%%) %6.2lf\n", _amount * 0.12);
printf("Discounted total $%6.2lf\n", total);
}
else{
total = _amount * (1 - 0.10);
printf("Teacher's discount (10%%) %6.2lf\n", _amount * 0.10);
printf("Discounted total $%6.2lf\n", total);
}
printf("Sales tax (5%%) %6.2lf\n", total * 0.05);
printf("Total $%6.2lf\n", total * 1.05);
}
double non_teacher(double _amount)
{
printf("Total purchases $%6.2lf\n", _amount);
printf("Sales tax (5%%) %6.2lf\n", _amount * 0.05);
printf("Total $%6.2lf\n", _amount * 1.05);
}
int main()
{
double amount;
char is_teacher;
printf("KEITH'S SHEET MUSIC CALCULATOR\n");
printf("Please enter the total amount for purchase ($):\n");
scanf("%lf", &amount);
printf("Are you a music teacher? ");
scanf("%c", &is_teacher);
printf("\n");
printf("RECEIPT\n");
if(is_teacher == 'Y')
{
teacher_total(amount);
}
else{
non_teacher(amount);
}
system("PAUSE");
return 0;
}
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
double teacher_total(double _amount)
{
double total;
printf("Total purchases $%6.2lf\n", _amount);
if(_amount >= 100)
{
total = _amount * (1 - 0.12);
printf("Teacher's discount (12%%) %6.2lf\n", _amount * 0.12);
printf("Discounted total $%6.2lf\n", total);
}
else{
total = _amount * (1 - 0.10);
printf("Teacher's discount (10%%) %6.2lf\n", _amount * 0.10);
printf("Discounted total $%6.2lf\n", total);
}
printf("Sales tax (5%%) %6.2lf\n", total * 0.05);
printf("Total $%6.2lf\n", total * 1.05);
}
double non_teacher(double _amount)
{
printf("Total purchases $%6.2lf\n", _amount);
printf("Sales tax (5%%) %6.2lf\n", _amount * 0.05);
printf("Total $%6.2lf\n", _amount * 1.05);
}
int main()
{
double amount;
char is_teacher;
printf("KEITH'S SHEET MUSIC CALCULATOR\n");
printf("Please enter the total amount for purchase ($):\n");
scanf("%lf", &amount);
printf("Are you a music teacher? ");
getchar(); //这里需要把回车换行符从缓存中拿走,你的scanf直接跳出不执行就是因为缓存中还有数据你第一个scanf时留下的'\n',第二个scanf直接就拿'\n'作为它需要的数据了,然后is_teacher == '\n',然后就直接执行else里面的 non_teacher(amount);所以你需要把第一次scanf后的缓存中的'\n'拿走。可以用getchar();
scanf("%c", &is_teacher);
printf("\n");
printf("RECEIPT\n");
if(is_teacher == 'Y')
{
teacher_total(amount);
}
else{
non_teacher(amount);
}
system("PAUSE");
return 0;
}