Thread: Easy one: How to hide variables equal to 0

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    1

    Easy one: How to hide variables equal to 0?

    Good morning. I'm starting to programming. I'm trying to run a programm that breaks down money to pieces defined ($500, $200, $100, etc). The problem i'm having is that i only needs it to show me the result of those values different to 0.

    This is my code

    int main()
    {
    int billet500, billet200, billet100, billet50, billet20, billet10, billet5, piece2, piece1, x, argent;


    printf("Veuillez entrer la somme d'argent\n");
    scanf("%d", &x);


    argent = x;


    billet500 = argent/500;
    argent = argent%500;
    billet200 = argent/200;
    argent = argent%200;
    billet100 = argent/100;
    argent = argent%100;
    billet50 = argent/50;
    argent = argent%50;
    billet20 = argent/20;
    argent = argent%20;
    billet10 = argent/10;
    argent = argent%10;
    billet5 = argent/5;
    argent = argent%5;
    piece2 = argent/2;
    argent = argent%2;
    piece1 = argent;


    printf("\n");
    printf("\n");
    printf("\n");


    printf("%d = %d *500 + %d *200 + %d *100 + %d *50 + %d *20 + %d *10 + %d *5 + %d *2 + %d *1 \n",x, \
    billet500, billet200, billet100, billet50, billet20, billet10, billet5, \
    piece2, piece1);



    --------------------

    I need the program to show only the "billet - pieces" with a value different than 0

    Example:

    Saisie somme en Euro: 1002
    1002 = 2 * 500 + 1 * 2

    and not to print

    1002= 2 * 500 + 0 * 200 + 0 *100..... etc.


    I would apprecciate your help.

    Thanks!!!
    Last edited by giancarlo2222; 04-23-2020 at 02:24 PM. Reason: i may have not made myself clear

  2. #2
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    306
    Instead of printing exhaustively using all your variables, print the ones after checking that they are non-zero (if-else statements). Use arrays for representation of currency/bills, same for the number of each bill required. Share your code using CODE tags. Read Forum guidelines, help and FAQ.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg fault in easy, easy code
    By lisa1901 in forum C++ Programming
    Replies: 11
    Last Post: 12-10-2007, 05:28 AM
  2. Console hide
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-17-2004, 04:45 AM
  3. Easy question, (should be) easy answer... ;-)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-12-2002, 09:36 PM
  4. Variables do not equal functions!!!
    By me@burk. in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 06:24 AM
  5. Why do variables equal functions?
    By Griffin2020 in forum C Programming
    Replies: 13
    Last Post: 03-23-2002, 01:41 AM

Tags for this Thread