我是編程新手,想讓我的程序獲得一個給定的數字,加倍,然後在用戶輸入多天的情況下繼續加倍。我做了這個循環,它的工作原理,但最終的數字是負面的。我不知道如何阻止它出現負面情況,並希望得到任何幫助。Printf出現負數
int main(void)
{
int d;
int s;
float a;
do
{
printf ("Please enter the amount of days in the month: ");
d = GetInt();
} while (d > 31 || d < 28);
do
{
printf("Please enter the amount of pennies you start will start with: ");
s = GetInt();
} while(s < 0);
do
{
s = s * 2;
d = d - 1;
a = s/100.0;
printf("%f\n", a);
} while(d > 0);
return 0;
}
's'和'd'從哪裏來?他們的初始價值是什麼? – 2013-03-05 21:18:33
知道s,d和a是什麼也是有幫助的。他們是32位整數嗎? – 2013-03-05 21:20:17
發佈「相關」代碼 - 所有值的定義和初始值至少爲 – KevinDTimm 2013-03-05 21:24:49