2016-12-15 41 views
-1

check50給人怪異的輸出,請幫助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」,總計)聲明的printf(總),但它導致編譯錯誤 編譯使用 鐺-ggdb3 -O0 -std = C11 -Wall -Werror -Wshadow greedy.c -lcs50 -lm -o貪婪

回答

0

代替此: printf("%d",total); 請使用以下方式試用: printf("%d\n",total);

+0

謝謝您現在可以使用 – ydj