if statement problem

+1 Hayden Kuk · November 11, 2015
<code>
#include <stdio.h>
#include <stdlib.h>
#include "structure.h"

int main()
{
    struct user hayden;
    int answer;

    puts("Enter userID : \n");
    gets(&hayden.userID);

    puts("Enter your first name : \n");
    gets(&hayden.firstName);

    puts("Enter your last name : \n");
    gets(&hayden.lastName);

    printf("Enter your age : \n");
    scanf(" %d", &hayden.age);

    printf("Enter your weight : \n");
    scanf( " %f", &hayden.weight);

    printf("Would you check your information? Y/N \n");
    scanf(" %d", &answer);

    if(answer == 'Y')
    {
        answer = 1;
    }
    else if(answer == 'y')
    {
        answer = 1;
    }
    else if(answer == 'N')
    {
        answer = 0;
    }
    else if(answer == 'n')
    {
        answer = 0;
    }
    else
    {
        return 0;
    }

    if(answer == '1')
    {
        printf(" User ID : %s \n", hayden.userID);
        printf(" First name : %s \n", hayden.firstName);
        printf(" Last name : %s \n", hayden.lastName);
        printf(" age : %d \n", hayden.age);
        printf(" weight : %.2f \n", hayden.weight);
    }

       return 0;
    }
</code>

<code>
struct user {
char userID[20];
char firstName[25];
char lastName[25];
int age;
float weight;
};

</code>

previously written codes are main and structure code respectively,

I think the main code works perfectly fine until I type input down to my body weight
and when I enter input to "answer"

if statement does not seem to work. Why?

Post a Reply

Replies

Oldest  Newest  Rating
0 Hayden Kuk · November 12, 2015
Krootushas Gesu/ I believe I know, vaguely also I currently fixed the problem by different method.

& was not necessarily a problem 
  • 1

C

107,222 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator