如何计算和打印;分面值;C #包括 int getAmount()//索要金额 int convert()//这将把数量分为50、20和10 常量int MAXAMUNT=95//问题状态输入的最大金额可以是95 常量int MINAMOUNT=5;//最小数量可以是5 //获取金额 int getAmount(金额){ printf(“输入金额:%d\n”,金额); scanf(“%d*c”和金额); 如果(金额最大金额){ printf(“输入金额b/w 5-95”); 回报(金额); } 回报(金额); } //这会将金额转换为多少美分 整数转换(整数金额){ } int main(){ 整数金额=0; //金额类型 常数int五分之一=50; 常数整数二十分=20; const int tencents=10; 常数int五个元素=5; 金额=getAmount(金额); 返回(0); }

如何计算和打印;分面值;C #包括 int getAmount()//索要金额 int convert()//这将把数量分为50、20和10 常量int MAXAMUNT=95//问题状态输入的最大金额可以是95 常量int MINAMOUNT=5;//最小数量可以是5 //获取金额 int getAmount(金额){ printf(“输入金额:%d\n”,金额); scanf(“%d*c”和金额); 如果(金额最大金额){ printf(“输入金额b/w 5-95”); 回报(金额); } 回报(金额); } //这会将金额转换为多少美分 整数转换(整数金额){ } int main(){ 整数金额=0; //金额类型 常数int五分之一=50; 常数整数二十分=20; const int tencents=10; 常数int五个元素=5; 金额=getAmount(金额); 返回(0); },c,C,所以这个问题有一个解决方案,但我不完全理解它,我很确定我们班上的每个人都会使用相同的代码,不想被剽窃打一巴掌,我想知道如何做得不同 请尝试以下代码: #include < stdio.h > int getAmount(); //Asks for amount int convert(); //This will divide the amount into how many 50's 20's and ten's const int MAXAMOUNT = 95; //Quest

所以这个问题有一个解决方案,但我不完全理解它,我很确定我们班上的每个人都会使用相同的代码,不想被剽窃打一巴掌,我想知道如何做得不同 请尝试以下代码:

#include < stdio.h >

int getAmount(); //Asks for amount
int convert(); //This will divide the amount into how many 50's 20's and ten's
const int MAXAMOUNT = 95; //Question states max amount entered can be 95
const int MINAMOUNT = 5; // and min amount can be 5

//getting the amount
int getAmount(amount) {
    printf("Enter the amount: %d\n", amount);
    scanf("%d*c", & amount);
    if (amount < MINAMOUNT || amount > MAXAMOUNT) {
        printf("Enter an amount b/w 5-95");
        return (amount);
    }
    return (amount);
}


//this will convert the amount to how many cents
int convert(int amount) {

}

int main() {
    int amount = 0;
    //types of amount
    const int fiftycents = 50;
    const int twentycents = 20;
    const int tencents = 10;
    const int fivecents = 5;

    amount = getAmount(amount);

    return (0);
}
#包括“stdio.h”
常量int MAXAMUNT=95//问题状态输入的最大金额可以是95
常量int MINAMOUNT=5;//最小数量可以是5
常数int五分之一=50;
常数整数二十分=20;
const int tencents=10;
常数int五个元素=5;
//获取金额
int getAmount(){
整数金额;
printf(“输入金额:”);
scanf(“%d*c”和金额);
如果(金额最大金额){
printf(“输入金额b/w 5-95”);
返回-1;
}
退货金额;
}
//这会将金额转换为多少美分
无效转换(整数金额)
{
整数全部五十=(整数)(金额/五分之一);
金额=金额-全部五十*五分之一;
整数全部二十=(整数)(金额/二十美分);
金额=金额-全部二十*二十美分;
int allten=(int)(金额/腾讯);
金额=金额-全部十家腾讯;
全部五个整数=(整数)(金额/五元);
金额=金额-全部五个*5个要素;
printf(“50%d,20%d,10%d,5%d”,共五十,共二十,共十,共五);
}
int main(){
int amount=getAmount();
如果(金额!=-1)
{
折算(金额);
}
返回0;
}

函数
convert
计算金额中有多少50美分,在找到所有50美分后,它计算所有20美分,以此类推。

我只需从最高值开始使用除法和提醒

如果金额是美元,你必须先乘以100。 然后:


然后五十、二十、十、五和美分是你硬币的数字

我的意思是你可以用其他名称来表示函数和属性不断从你的值中减去50,直到小于50,然后尝试减去20,直到小于20,然后10,每次计算减法的次数。这是您每人的硬币数。谢谢。。我更明白这一点。
#include "stdio.h"

const int MAXAMOUNT = 95; //Question states max amount entered can be 95
const int MINAMOUNT = 5; // and min amount can be 5

const int fiftycents = 50;
const int twentycents = 20;
const int tencents = 10;
const int fivecents = 5;

//getting the amount
int getAmount() {
    int amount;
    printf("Enter the amount: ");
    scanf("%d*c", & amount);
    if (amount < MINAMOUNT || amount > MAXAMOUNT) {
        printf("Enter an amount b/w 5-95");
        return -1;
    }
    return amount;
}


//this will convert the amount to how many cents
void convert(int amount) 
{
    int allfifty = (int)(amount/fiftycents);
    amount = amount - allfifty * fiftycents;
    int alltwenty = (int)(amount/twentycents);
    amount = amount - alltwenty * twentycents;
    int allten = (int)(amount/tencents);
    amount = amount - allten * tencents;
    int allfive = (int)(amount/fivecents);
    amount = amount - allfive * fivecents;
    printf("50 - %d, 20 - %d, 10 - %d, 5 - %d", allfifty, alltwenty, allten, allfive);
}

int main() {
    int amount = getAmount();
    if (amount != -1)
    {
        convert(amount);
    }
    return 0;
}
fifties = amount/50;
amount = amount % 50; // put back in amount the rest of the fist division. 
twenties = amount / 20;
amount =  amount % 20;
tens = amount / 10;
amount =  amount % 10;
fives = amount / 5;
cents =  amount % 5;  // finally the rest is in cents.