解決表達的時候,這裏是我的代碼獲取-2147483648十進制
int OP, NP, first, second, third, blankets, remainder;
printf("How many people are knitting blanket squares at the beginning of the week?\n");
scanf("%d", &OP);
printf("How many new people are knitting blanket squares each day?\n");
scanf("%d", &NP);
//formula
first = 1 + NP;
second = pow(first,7);
third = OP * second;
blankets = third/(double)60;
remainder = third - blankets * 60;
printf("%d blanket squares will be made this week!\n", third);
printf("You will be able to make %d blankets and start next week with %d squares.", blankets, remainder);
這是除了當我進入NP的地方小數(如.5)足夠的身體。當我這樣做的時候,我得到了一個溢出,並且它爲第一個printf輸出值-2147483648。我需要改變數據類型嗎?對不起,一個非常簡單的問題,我很新。
是.5'int'? –
您應該嘗試的第一件事是在讀取它們之後立即顯示'OP'和'NP'的值:'printf(「OP =%d,NP =%d \ n」,OP,NP);' –
@奧利弗·查爾斯沃斯另一種說法:針織人是否有可能被削減一半?當然(閱讀:我希望)不是。 C不會浪費資源來防止調用未定義行爲的無意義輸入。 –