dimanche 27 novembre 2022

How do I print Not Available instead of a price with a 50% chance?

I have this buy and sell game and on of its functions is to list down the items and its randomized prices. I want it to have a 50 percent chance to show "NOT AVAILABLE" while the other 50 percent, it will show the randomized price. Also, did I randomize ir correctly? there needs to be a 50 perccent chance of showing either the text or the price. Thank you!

This is my code right now but I think there is a way to simplify it more and a way for me to not code it like this.

if((pItem1 = rand() % (70000 - 40000 + 1) + 40000) % 100 > 50)
    {    printf("ITEM 1                                       %dG\n", pItem1);}
else
    {    printf("ITEM 1                                   NOT AVAILABLE\n");}



Aucun commentaire:

Enregistrer un commentaire