" C program " Adding Questions and using Answeres in Calculations

I am trying to do a BMI calculator.

My code below asks for weight and height below and then returns the BMI result with the definition of your weight status.

I would like to be able to do the following

1. What is your name?
(Answer) xyz
2. How Old are you?
(Answer) 25
3. How much do you weigh in Kg's?
(Answer) 90
4. What is your height in Meters
(Answer) 1.8

Then from the code it takes this information and calculates the BMI and returns

"xyz you are 25 years old your BMI is (result of the calculation your status is (what ever corresponds to that result.

I would be most grateful if I can be pointed in the right direction to do this.

Many thanks

Rodney

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  #include <windows.h>

enum 
  {
  black,
  dark_blue,
  dark_green,
  dark_cyan,
  dark_red,
  dark_magenta,
  dark_yellow,
  light_gray,
  dark_gray,
  light_blue,
  light_green,
  light_cyan,
  light_red,
  light_magenta,
  light_yellow,
  white
  };

int getcolors()
  {
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  GetConsoleScreenBufferInfo(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    &csbi
    );
  return csbi.wAttributes;
  }

int getfgcolor()
  {
  return getcolors() & 0x0F;
  }

int getbgcolor()
  {
  return getcolors() >> 4;
  }

void setfgcolor( int color )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    (getcolors() & 0xF0) | (color & 0x0F)
    );
  }

void setbgcolor( int color )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    ((color & 0x0F) << 4) | (getcolors() & 0x0F)
    );
  }

void setcolors( int fg, int bg )
  {
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ), 
    ((bg & 0x0F) << 4) | (fg & 0x0F)
    );
  }

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <windows.h>

int main()
{
  
   float height, weight,bmi;
   
   setfgcolor( black );
   setbgcolor( light_magenta );
   
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("xx                                                                       xx\n");
   printf("xx                                                                       xx\n");
   printf("xx Body Mass Index (BMI) is a number calculated from a person's weight   xx\n");
   printf("xx and height. BMI provides a reliable indicator of body fatness for     xx\n");
   printf("xx most people and is used to screen for weight categories that may      xx\n");
   printf("xx lead to health problems.                                              xx\n");
   printf("xx                                                                       xx\n");
   printf("xx                                                                       xx\n");
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
   printf("\n");
   printf("\n");
   
   Sleep(6000);
   system("cls");
   printf("\n");
   setbgcolor( white );
    setbgcolor( light_green ); 
 
   printf("Enter Weight in Kg's and Height in METERS  \n");
  
   
   scanf("%f%f", &weight, &height );

   bmi = weight/(height*height);
 
system("cls");
 

   printf("           Your BMI is %.2f\n           ",bmi);
   

   
   if(bmi<=18.5) {
                 
                 printf("you are under weight\n");
}
   else
   
   
   
  if(bmi<=25){
                printf("your weight is normal\n");
}
else



if(bmi<=50){
            printf("you are over weight\n");

            } 
else



if(bmi<=200){
     printf("you are obese\n");      
}
return(0);
}
Your program compiles and seems to execute.
What is your question?

Note. Your program will exit immediately after displaying the result.
See the following thread.
http://www.cplusplus.com/forum/beginner/1988/
My question is

My code asks for weight and height below and then returns the BMI result with the definition of your weight status.

I would like to be able to do the following from the below questions

1. What is your name?
(Answer) xyz
2. How Old are you?
(Answer) 25
3. How much do you weigh in Kg's?
(Answer) 90
4. What is your height in Meters
(Answer) 1.8

Then from the code it takes this information and calculates the BMI and returns

"xyz you are 25 years old your BMI is (result of the calculation your status is (what ever corresponds to that result.
Topic archived. No new replies allowed.