[Help] Something wrong with the age input and output.

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
78
79
#include <stdio.h>
#include <string> 
#include <conio.h>
#include <stdlib.h>

void main()
{
	char name[20],sex,res,sex_r[20];
	char remark[50] ;
	float height,weight;
	int age;

	do{
		char remark[20] ;
		printf("Enter Name: ");
		gets(name);
		printf("Enter Age: ");
		flushall();
		scanf("%d",&age);     //something wrong with age 
		printf("Enter Sex (M/F): ");
		flushall();
		scanf("%c",&sex);
		printf("Enter Height (m): ");
		scanf("%f",&height);
		printf("Enter Weight (kg): ");
		scanf("%f",&weight);

		if(weight<=70)
		{

			
			if(height>=1.8)
			{
				strcpy(remark,"You are VERY TALL for your weight");
			}

			else if(height>1.6 && height<1.8)
			{
				strcpy(remark,"You are TALL for your weight");
			}

			else
			{
				strcpy(remark,"You are QUITE SHORT for your weight");
			
			}
		}

		else
		{
			strcpy(remark,"Your weight is ideal");
			
		}

		if(sex='F')
		{
			strcpy(sex_r,"Female");
		}

		else 
		{
			strcpy(sex_r,"Male");
			
		}

		printf("\n%s is %d years old. You are %s.\nYour height is %.2fm and weight is %.2fkg. %s.\n\n",name,age,sex_r,height,weight,remark);
		printf("\n%d",age);
		

		printf("Do you want to continue? (Y/N): ");
		
		flushall();
		res=getch();
		system("cls");

	}while(res!='N' || res!='n');

		printf("\nBye");
}


The age output always show 0 regardless what age I input.
Thanks.
Since flushall() isn't standard (it comes from the conio.h header file) we have no clue what it's actually doing in the background. Have you tried omitting the flushall() function before age to see if that fixes your issue?

If you find out that you need the "flushall()" function, I suggest trying to use fflush(stream) instead since it is standard and will do the same thing on my system as it does on yours.
Topic archived. No new replies allowed.