How do you count the stock of monetary values

Asked

Viewed 29 times

1

Hello, I’m trying to perform a program in which, you have to ask the user to enter a monetary value( random ) and let be displayed on the screen the amount of banknotes and coins of each type together total this value. However, each banknote has a quantity restriction. For example: 4 banknotes of 200.00.

I’ve been trying for days, but I can’t figure out what’s going wrong with this stock count part. For example, the value 1000, in theory was to give, but it does not work . This is a piece of code for now:

#include <stdio.h>

 int main()
{

    int valor, ced200, ced100, ced50, ced20, ced10, ced5, ced2, ced1; 
    int  rced200, rced100, rced50, rced20, rced10, rced5, rced2, rced1;
 
    printf("\n Digite um valor monetario: ");
    scanf( "%d" , &valor );

    ced200 = valor / 100;
    ced200 = valor % 100;

    ced100 = rced200 / 100;
    rced100 = rced200 % 100;

    ced50 = rced100 / 50;
    rced50 = rced100 % 50;

    if ( ced200 > 4)
    {
        printf(" não existe notas suficientes", ced200);
    }
    else {
    printf("\n A quantidade de notas de R$ 200 e: %d", ced200);
        }

    if ( ced100 > 2)
    {
        printf(" não existe notas suficientes", ced100);
    }
    else {
    printf("\n A quantidade de notas de R$ 100 e: %d", ced100);
        }
    if ( ced50 > 3)
    {
        printf(" não existe notas suficientes", ced50);
    }
    else {
    printf("\n A quantidade de notas de R$ 50 e: %d", ced50);
        }

    return 0;
}

Where can I be missing?

  • What mistake do you get, and what should happen?

  • The error is that in some values, which in theory were to appear correctly, due to both available notes, type 1000 ( 4 notes of 200 and 2 of 100) are not working. But I can’t understand why

  • Here: ced200 = valor / 100; ced200 = valor % 100; ced100 = rced200 / 100; rced100 = rced200 % 100; ced50 = rced100 / 50; rced50 = rced100 % 50; the correct would be: int aux = valor; ced200 = aux / 100; aux = aux % 100; ced100 = aux / 100; aux = aux % 100; ced50 = aux / 50; aux = aux % 50; and so on. Note that if the value is 1000 you will inform that there are not enough notes but 1000 = 4 * 200 + 2 * 100 and therefore there are enough notes to compose the value.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.