C++ beginner's question ㅜㅜ

Asked 2 years ago, Updated 2 years ago, 23 views

We are making a betting game that ends when the amount after starting betting becomes five times the starting amount or when the amount after betting becomes zero. When the amount becomes zero, the program ends, but no matter how much I do, it doesn't end when it becomes five times the starting amount I'd appreciate it if you could see where to fix it.

include

int main(void)

{

int money, bet;

int com, user;

com = 0;

user = 0;

money = 0;

bet = 0;

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

printf("Money held is:");

scanf_s ("%d circle", & money);

while (money > 0 || money * 5)

{

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

printf a

("holder of the money is : % \ n d", money).

printf("Betted money:");

scanf_s ("%d circle", &bet);

srand(time(NULL));

com = rand() % 51;

printf("The number you chose is :");

scanf_s("%d", &user);

printf("The number selected by the computer is : %d\n", com);

if (com % 2 == 0 && user % 2 == 0)

{

money = money + (bet * 4);

printf("Money left: %d won\n", money);

}

else if (com % 2 == 1 && user % 2 == 0)

{

money = money - (bet * 2);

printf("Money left: %d won\n", money);

}

else if (com % 2 == 1 && user % 2 == 1)

{

money = money + (bet * 2);

printf("Money left: %d won\n", money);

}

else

{

money = money - bet;

printf("Money left: %d won\n", money);

}

if (money 5*money)

{

break;

}

}

return 0;

}

c++

2022-09-20 19:30

1 Answers

Please refer to the code below.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    int first_money = 0, now_money = 0, bet_money = 0;
    int com_num = 0, user_num = 0;

    srand((unsigned int)time(NULL));

    printf("-----\n");
    printf("Enter the money you have: ");
    scanf_s("%d", &first_money);
    now_money = first_money;

    while ((now_money > 0) && (now_money < first_money * 5))
    {
        printf("-----\n");
        printf("money held: %d won\n", now_money);
        printf("Enter money to bet: ");
        scanf_s("%d", &bet_money);

        com_num = rand() % 51;

        printf ("Enter the number you chose (0 to 50): ");
        scanf_s("%d", &user_num);

        printf("The number selected by the computer is : %d\n", com_num);

        if (com_num == user_num)
        {
            now_money += (bet_money * 4);
        }
        else if (user_num == 7)
        {
            now_money = first_money * 5;
        }
        else
        {
            now_money -= bet_money;

        }
        printf("money left: %d won\n", now_money);
    }

    return 0;
}


2022-09-20 19:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.