summaryrefslogtreecommitdiff
path: root/infection_simulator.c
blob: ed7232b9dcc68de1ded1cb5da4bd145e25c660cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <math.h>

void current();
void print_menu();

int main()
{
    int choice;
    do {
        print_menu();
        scanf("%d", &choice);
        switch (choice)
        {
            case 1:
                current();
                break;
            case 2:
                printf("Exiting...\n");
                break;
            default:
                printf("Invalid choice. Please try again.\n");
        }
    }
    while (choice != 2);
    return 0;
}

void print_menu()
{
    printf("Choose:\n");
    printf("1. Get the output and percentage\n");
    printf("2. Exit the program\n");
    printf("Enter your choice: ");
}

void current()
{
    int days;
    float infected = 7.0;
    float infected_today = 7.0;
    int withdraw;
    const int total = 2440;
    const float fee = 9972.0;

    printf("Enter days: ");
    scanf("%d", &days);

    if (days <= 0)
    {
        printf("Invalid number of days. Please enter a positive number.\n");
        return;
    }

    for (int i = 0; i < days && infected <= total; i++)
    {
        infected += infected_today * 0.2;
        infected_today *= 1.2;
        if (i < 14)
	{
            withdraw = (int)infected;
        }
    }

    if (infected > total)
    {
        infected = total;
    }

    int total_rounded = (int)infected;
    float percentage = (infected / total) * 100;
    float not_infected = total - withdraw;
    float discount = not_infected * (fee * 0.05);
    float loses = withdraw * fee + discount;

    printf("The number of infected students is: %d, a percentage of %.2f, the total losses are $%.0f corresponding to %d students, the number of students receiving a 5 percent discount is %.0f, and the total amount given in discounts is $%.0f\n", total_rounded, percentage, loses, withdraw, not_infected, discount);
}