I am creating a simple application to keep track how long I am working. A user enters the amount of minutes of work they are doing and the program will keep track of the total until termination. The issue is after the first time the program is run it to prints out its first statement twice. I have it inside an infinite loop and I don't have a great grasp on scanf and printf so I think that is where my failure lies. Any help would be appreciated.
This is what the program looks like:
#include <stdlib.h>
#include <stdio.h>
void logic(int *minutesWorked, int *hoursWorked, int *totalMinutesWorked);
int main(void)
{
int minutesWorked = 0;
int hoursWorked = 0;
char letter = 0;
int totalMinutesWorked = 0;
while (1) {
printf("Enter I for input or T for total\n");
scanf("%c", &letter);
if (letter == 'i' || letter == 'I') {
printf("Please enter minutes worked\n");
scanf("%d", &minutesWorked);
logic(&minutesWorked, &hoursWorked, &totalMinutesWorked);
}
else if (letter == 't' || letter == 'T') {
printf("Hours worked is %d and minutes worked is %d\n", hoursWorked,totalMinutesWorked);
}
}
return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
void logic(int *minutesWorked, int *hoursWorked, int *totalMinutesWorked)
{
*totalMinutesWorked += *minutesWorked;
if (*totalMinutesWorked >= 60) {
*hoursWorked += *totalMinutesWorked / 60;
*totalMinutesWorked = *totalMinutesWorked % 60;
}
} /* ----- end of function logic ----- */
And this is an example of what it displays:
Enter I for input or T for total
I
Please enter minutes worked
100
Enter I for input or T for total
Enter I for input or T for total
I
Please enter minutes worked
33
Enter I for input or T for total
Enter I for input or T for total
T
Hours worked is 2 and minutes worked is 13
Enter I for input or T for total
Enter I for input or T for total