現在我的程式快完成了,但我需要一點幫助,因為數學不正確。
由于我用歐元鏈接到 menge,我認為腳本將使用 414。但它以某種方式使用了另一個數字。
我仍然對 xyz.c 檔案和 header.h 檔案有點困惑。我是否應該將資料條目放入 .h 檔案并將函式放入 .c 檔案。我應該如何正確使用它們。
int main()
{
double euro, ats, sum;
// Eingabe euro
printf("Input: ");
scanf("%lf", &euro);
ats = 13.760; //fixierter Wert für die Umrechnung
// Umrechung Euro mal ats
sum = euro * ats;
printf("Ausgabe:\n");
printf("%.0f Euro entspricht ca. %.0f Schilling\n", euro, sum);
//Textausgabe mit Geldnoten
int menge, geldnoten;
menge = euro;
// Stueckelung Noten
int stueckelung[SIZE] = {200,100,50,20,10,5,2,1};
for (int i = 0; i < SIZE; i )
{
geldnoten = menge / stueckelung[i];
if(geldnoten)
{
geldnoten = menge % stueckelung[i]; //uebriges Geld
printf("%d %d = %d \n", geldnoten, stueckelung[i],
geldnoten * stueckelung[i]);
}
}
return 0;
}
輸出:
Input: 414
Ausgabe:
414 Euro entspricht ca. 5697 Schilling
14 200 = 2800
14 100 = 1400
14 50 = 700
14 20 = 280
4 10 = 40
4 5 = 20
0 2 = 0
0 1 = 0
輸出的目標是這句話: In Geldscheinen und Münzen: 2 Scheine mit Wert 200, 1 Schien mit Wert 10 and 2 Münzen mit Wert 2
翻譯將是:在紙幣和硬幣中:2 張紙幣 200、1 張紙幣 10 和 2 枚 2 硬幣。
我在這里用 printf 命令苦苦掙扎,我該怎么做?
uj5u.com熱心網友回復:
如果我正確理解了這個問題,你需要在回圈的每次迭代中減少menge(geldnoten * stueckelung[i]音符數量的乘積geldnoten,和每個音符的值, ):stueckelung[i]
for (int i = 0; i < SIZE; i )
{
geldnoten = menge / stueckelung[i];
if(geldnoten)
{
// geldnoten = menge % stueckelung[i]; // not this
menge -= geldnoten * stueckelung[i]; // this instead
printf("%d * %d = %d\n", geldnoten, stueckelung[i],
geldnoten * stueckelung[i]);
}
}
使用 input 414,上面會產生這個輸出:
Input: 414
Ausgabe:
414 Euro entspricht ca. 5697 Schilling
2 * 200 = 400
1 * 10 = 10
2 * 2 = 4
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/456455.html
上一篇:GCC在哪里找到printf?我的代碼在沒有任何#include的情況下作業
下一篇:新手:將指標傳遞給函式
