check50给出奇怪的输出请帮忙
#include <cs50.h>
#include <stdio.h>
#include <math.h>
int main(void)
{
int amount,n25,n10,n5,n1,total;
int rem;
float gamount;
printf("O hai!");
do{
printf("How much change is owed?\n");
gamount = GetFloat();
}while(gamount<0);
amount = (int) round(gamount *100.00);
rem = round(amount);
n25 =(int) rem /25;
rem = rem %25;
n10 = rem /10;
rem = rem%10;
n5 = rem /5;
rem = rem%5;
n1 = rem /1;
rem = rem%1;
total = n25+n10+n5+n1;
printf("%d",total);
return 0;
}
check50输出:
*~/workspace/pset1/ $ check50 2015.fall.pset1.greedy greedy.c
:) greedy.c exists
:) greedy.c compiles
:( input of 0.41 yields output of 4
\ expected output, but not "4"
:( input of 0.01 yields output of 1
\ expected output, but not "1"
:( input of 0.15 yields output of 2
\ expected output, but not "2"
:( input of 1.6 yields output of 7
\ expected output, but not "7"
:( input of 23 yields output of 92
\ expected output, but not "92"
:( input of 4.2 yields output of 18
\ expected output, but not "18"
:) rejects a negative input like -.1
:) rejects a non-numeric input of "foo"
:) rejects a non-numeric input of ""
https://sandbox.cs50.net/checks/f9c8501c99a848df82d8bd0df231a6ea
我尝试将printf(“%d”,total)语句更改为printf(total)但是会导致编译错误 编译使用 clang -ggdb3 -O0 -std = c11 -Wall -Werror -Wshadow greedy.c -lcs50 -lm -o greedy
答案 0 :(得分:0)
而不是:
printf("%d",total);
试着用这个:
printf("%d\n",total);