0
I need a program that calculates change for a $100 bill. He asks to enter which notes I want the change and so calculates how many notes of each I need to change 100. Numbers must always be integers . If you enter 0 first, you must ask for another value. Values must exit in ascending order. (ex. INPUT 10 20 - OUTPUT 20 20 20 20 10 10) I cannot develop the pro algorithm logic separates the right amount from each cell. If anyone can help I would be very grateful, I am desperate already haha. Any help is valid. : ) I started trying the individual values that need each note to reach 100, but does not evolve.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i, j, troco, n2=2, n5=5, n10=10, n20=20, n50=50, qn2, qn5, qn10, qn20, qn50;
printf("Digite o número da variedade de notas: ");
scanf("%d", &n);
int vet[n];
printf("Digite o valor das notas: \n ");
for(i=0, i<n; i++){
scanf("%d", vet[i]);
}
for(j=0; j<n; j++){ \\ troco individual de cada nota para torcar 100
if(vet[i]==n2){
qn2 = (100/ vet[i]);
}if(vet[i]==n5){
qn5 = (100/ vet[i]);
}if(vet[i]==n10){
qn10 = (100/ vet[i]);
}if(vet[i]==n20){
qn20 = (100/ vet[i]);
}if(vet[i]==n50){
qn50 = (100/ vet[i]);
}
}
return 0;
}
Note that your solution is meaningless. If the value reported for n is 2 and you report 10 for vet[0] and 20 for vet[1] then you will get 10 for qn10 and 5 for qn20 which will be quantities that do not match the expected result. You didn’t define how to compose the result, it says that for the example input, the output would be 20 20 20 20 20 20 20 10 10 10 but why not 20 10 10 10 10 10 or 20 20 20 20 20 10 10 10 10? Or any response will be accepted?
– anonimo
So, n should be the amount of the variety, that is, if I want my change in 10s and 20s, then my n should be 2.I thought I would read the notes, store it in the array and then read its size as well. The result should come out in ascending order. The intention of N2, N5, N10 and so on is to know the value of the individual change of each value for 100, for 10 real I have 10 notes to reach 100, for 20 real I have 5 20 notes to reach 100 and so on. I started thinking like this to see if it evolved in logic you know, use as resolution feature and not as output.
– Vitória Rocha
You need to think more about the solution. For example you accept any input but if the input is 20 50 there will be no solution with both the notes.
– anonimo
In this case I print a message. It is a condition, but the difficulty is even in doing the counting. I am trying here, who knows, faith. :)
– Vitória Rocha
Think mathematically, for each value vi reported there must be an amount qi, greater than zero, such that the sum of qi*vi is 100.
– anonimo