我的程序有问题 - 我想隐藏一些输出。
int main(void){
char redo;
int money, x[6],y[6],total;
x[0] = 1000; x[1] = 500; x[2] = 200; x[3] = 100; x[4] = 50; x[5] = 20;
do{
system("cls");
printf("Enter your Money: ");
scanf("%d", &money);
total = money;
printf("\nBreakdown:\n");
for(int i=0;money != 0 && i < 6; i++){
y[i] = ( money - (money % x[i]) )/x[i];
money = (money % x[i]);
printf("%10d x %d = %5d \n", x[i], y[i], (x[i] * y[i]));
}
printf("---------------------------\n");
printf("Total: %d",total);
if(money>0){
system("cls");
printf("Invalid Input !");
}
getch();
system("cls");
printf("\nEnter y or Y to continue: ");
scanf(" %c", &redo);
}while((redo == 'y')||(redo== 'Y'));
return 0;
}
我的输出显示:
Enter you Money: 9720
Breakdown:
1000 x 9 = 9000
500 x 1 = 500
200 x 1 = 200
100 x 0 = 0
50 x 0 = 0
20 x 1 = 20
----------------
total: 9720
我想隐藏result = 0的标签:
100 x 0 = 0
50 x 0 = 0
我希望我的输出是这样的:
Enter you Money: 9720
Breakdown:
1000 x 9 = 9000
500 x 1 = 500
200 x 1 = 200
20 x 1 = 20
----------------
total: 9720
有人知道怎么做吗?
答案 0 :(得分:1)
只需添加if
语句,不要打印您不想要的内容:
for(int i=0;money != 0 && i < 6; i++){
y[i] = ( money - (money % x[i]) )/x[i];
money = (money % x[i]);
if(y[i] != 0)
printf("%10d x %d = %5d \n", x[i], y[i], (x[i] * y[i]));
}