Answer the question
In order to leave comments, you need to log in
Why is the function not returning the desired value?
// I want the function to reset the entered value to a given limit and display the remainder. That is, when we enter 100, when dividing by 25, there is no remainder and 0 comes out, and if 99, then the remainder is 1. Tell me how to arrange? Outputs always "0" for any value.
#include <stdio.h>
int main(void)
{
int surrender = scanf_s("ENTER...");
int coin25 = 25,
coin10 = 10,
coin5 = 5,
coin1 = 1;
int countCoin25 = 0,
countCoin10 = 0,
countCoin5 = 0,
countCoin1 = 0;
while (coin25 > 0 && surrender - coin25 >= 0) {
surrender - coin25;
countCoin25++;
}
printf("SURRENDER IS %d " , countCoin25);
system("pause");
}
Answer the question
In order to leave comments, you need to log in
#include <iostream>
int main()
{
const int N = 4;
const int coinsValue[N] = {25, 10, 5, 1};
int coinsCount[N] = { 0, 0, 0, 0};
int sum;
std::cin >> sum;
for (int i = 0; i < N; ++i)
{
while (sum >= coinsValue[i])
{
coinsCount[i]++;
sum -= coinsValue[i];
}
std::cout << coinsCount[i] << " (" << coinsValue[i] <<
(coinsCount[i] == 1 ? ") coin\n" : ") coins\n");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question