我很難找出一種方法,從「放棄」超過5美元的1000美元獎學金和10美元500美元的獎學金計劃。我將如何在5和8之後從我已經擁有的東西中剪掉它?我的代碼是問題下面程序員的如何製作最多獎學金?
一個師,共創美好明天就是他們的獎學金捐贈基金。他們 每年向需要1000,500和250美元的學生的學生提供獎學金。 這些獎學金的資金來自以前的捐贈和 投資。
您將創建一個計劃來計算基金的年度利息,並確定可以獎勵1000美元,500美元和250美元的獎學金。 例如,如果基金在2016年9月30日有50萬美元,並且年利率爲3%,那麼基金在9月份的 年底將有515,000美元。這給他們$ 15,000作爲獎學金支付。
如果可能的話,基金會傾向於獎勵5美元1000美元的獎學金,10美元的獎學金和500美元的獎學金,以及更多的 250美元,因爲他們還有錢。 15,000美元的基金可以獎勵5千美元的獎學金,10 500美元的獎學金和20美元的250美元的獎學金。您的程序應該爲 用戶打印此信息。
如果這是不可能的,基金會將盡可能獎勵1000美元和500美元的獎學金。
例如,如果他們有4750美元,他們將獎勵4美元1000美元的獎學金,1500美元的獎學金和 美元250美元的獎學金。
輸入規格
- 的錢在基金的金額,N,爲一年前,其中n爲大於或等於 0(n可以包括小數)
- ,年百分比率p表示爲p大於零的整數。
輸出規範
輸出使用以下格式的結果:
X $1000 scholarships will be awarded.
Y $500 scholarships will be awarded.
Z $250 scholarships will be awarded
到目前爲止我的代碼:
#include <stdio.h>
#include <math.h>
//main function
int main() {
int ten, five, twofive, leftovers_ten, leftovers_five, scholarship_money;
float fund, interest;
printf("How much was in the fund last year?\n");
scanf("%f", &fund);
printf("What is the yearly percentage rate?\n");
scanf("%f", &interest);
scholarship_money = fund * (interest/100);
{
if(ten < 5) {
ten = scholarship_money/1000;
printf("%d $1000 scholarships will be awarded.\n", ten);
}
else {
ten = 5;
printf("5 $1000 scholarships will be awarded.\n");
}
}
leftovers_ten = scholarship_money - (ten * 1000);
{
if(five < 10) {
five = leftovers_ten/500;
printf("%d $500 scholarships will be awarded.\n", five);
}
else {
five = 10;
printf("10 $500 scholarships will be awarded.\n");
}
}
leftovers_five = leftovers_ten - (five * 500);
twofive = leftovers_five/250;
printf("%d $250 scholarships will be awarded.\n", twofive);
return 0;
}
像[這個家庭作業](http://cboard.cprogramming。COM/C編程/ 171235燦別人的幫助-着-GET-workings.html)?這是發佈在這裏的衆多金錢問題之一,新手的錯誤是在浮點工作。 –
@Weather Vane Money在任何數據類型中工作都有問題。 [各種問題](http://stackoverflow.com/a/32214586/2410359) – chux
@chux很好的答案,但你的水晶球說我們當地的儲蓄利率會下降到0.5%? –