0

After the user enter his weight for the first time it prints twice the choose gender line while i only want is to be printed once.

#include <stdio.h>

void main()
{
    float weightMen = 0, weightWomen = 0, temp = 0;
    int counterMen = 0, counterWomen = 0, i;
    char choice = ' ';

    while (temp != -1)
    {
        printf("Please choose your gender,\nM - for men\nF - for women\n");
        scanf_s("%c", &choice);

        if ((choice == 'M') || (choice == 'm'))
        {
            printf("Please enter your weight:\n");
            scanf_s("%f", &weightMen);
            temp = weightMen;

            if (temp == -1)
            {
                break;
            }
            else
            {
                weightMen += weightMen;
                counterMen++;
            }
            
        }
    }
    printf("%.2f", weightMen);
thesecretmaster
  • 1,950
  • 1
  • 27
  • 39
May Swisa
  • 23
  • 5
  • Change `scanf_s("%c", &choice);` to `scanf_s(" %c", &choice);`. That is, add space before `%c`. See the duplicate post for more details of why. – kaylum Mar 30 '22 at 11:58
  • 1
    Enable all warnings. `scanf_s("%c", &choice);` is missing an argument. "The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers apply to a pair of arguments" – chux - Reinstate Monica Mar 30 '22 at 12:16

0 Answers0