だから私は現在、CS50とCを学んでいると私は現在、PSET1からgreedy problemをやって、このプログラムの目的は、ユーザーに出力する彼は彼が負っています変更を受け取ることになりますコインの最低量です。たとえば彼が32セントの変更を取り戻せば、合計4コインのために1クォーター、1ニッケル、2ペニーが得られます。私はエラーを取得しておくコインをカウントするモジュロ関数を使用した後、彼が受け取るコインの枚数をカウントして、トラブルのかなりのビットを持ってきました:無効なオペランドをバイナリ表現に(「ダブル」と「ダブル」)なぜ誰かが明確にしたり、コードを修正するのを助けることができないのか、私には分かりません。あなたがfmod
使用する必要が誰かがこのコードのモジュロ関数がなぜ機能しないのか説明できますか?
#include <stdio.h>
#include <math.h>
int main(void) {
float coins;
int quarters, dimes, nickles, pennies;
// This part of the code prompts the user to input the amount of money that he's owed
// making sure that the value entered is positive and bigger than 0 or else the
// program will reprompt the user for input
do {
printf("How much money are you owed?");
coins = get_float();
} while (coins <= 0.0);
/* this is where the problem is, I'm trying to count the change given to the user with this
formula but the compiler keeps telling me that there is something wrong with the modolo
function that im using but im not sure what the problem is exactly */
quarters = coins/0.25;
dimes = (coins % 0.25)/0.10;
nickles = ((coins % 0.25) % 0.10)/0.05;
pennies = ((coins % 0.25) % 0.10) % 0.05;
int SumOfCoins = quarters + dimes + nickles + pennies;
printf("%i\n", SumOfCoins);
}
''%演算子は整数のみのために定義されています。 –
エラーメッセージをクリアすることができませんでした。 – Olaf
@EugeneSh。整数型に整数型を好む? – Bathsheba