Calculation problems

Am working on an addition program. On my program am trying to figure out the reason behind a scenario in which when input numbers for calculation, the output is only up to 99. After that it will start outputting numbers such as 1e02 2e02 and so on. When there is a decimal output, I seems that I cannot find any numbers after the decimal. The program only outputs whole numbers. Anybody who can help me out to solve this problem?

Belo is the program that am trying to use:

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
  #include <iostream>;
#include <iomanip>;

using namespace std;

int main()
{
double geslacht{ 0 }, bmi{ 0 }, gewicht{ 0 }, lengte{ 0 }, MINgezondgewichtMan{ 0 }, MAXgezondgewichtMan{ 0 }, MINgezondgewichtVrouw{ 0 }, MAXgezondgewichtVrouw{ 0 };
cout << "Voer uw geslacht in (man = 1, vrouw = 2): " << endl;
cin >> geslacht;

cout << "Voer uw gewicht in kg aub : " << endl;
cin >> gewicht;
cout << "" << endl;
cout << "Voer uw lengte in cm aub: " << endl;
cin >> lengte;
cout << "" << endl;

bmi = (gewicht / ((lengte / 100) * (lengte / 100)));
MINgezondgewichtMan = (20 * ((lengte / 100) * (lengte / 100)));
MAXgezondgewichtMan = (25 * ((lengte / 100) * (lengte / 100)));
MINgezondgewichtVrouw = (19 * ((lengte / 100) * (lengte / 100)));
MAXgezondgewichtVrouw = (24 * ((lengte / 100) * (lengte / 100)));
cout << setprecision(2) << "Uw BMI : " << bmi << endl;
cout << "" << endl;

if (geslacht == 1)
{
cout << "BMI voor een gezonde man ligt tussen de 20 en 25" << endl;
cout << "" << endl;
cout << "Een gezond gewicht voor u ligt tussen de " << setprecision(2) << MINgezondgewichtMan << " kg" << " en de " << MAXgezondgewichtMan << "kg" << endl;
cout << "" << endl;
if (bmi > 25)
cout << "U heeft overgewicht";

else if (bmi > 20)
cout << "Uw gewicht is prima";
else
cout << "U heeft ondergewicht";
}

if (geslacht == 2)
{
cout << "BMI voor een gezonde vrouw ligt tussen de 19 en 24" << endl;
cout << "Een gezond gewicht voor u ligt tussen de " << setprecision(2) << MINgezondgewichtVrouw << " kg" << " en de " << MAXgezondgewichtVrouw << "kg" << endl;
cout << "" << endl;
if (bmi > 24)

cout << "U heeft overgewicht";
else if (bmi > 19)
cout << "Uw gewicht is prima";
else
cout << "U heeft ondergewicht";
}
cout << "" << endl;
return 0;


}

Ref: https://www.theengineeringprojects.com/2021/11/oop-concepts-in-c.html
Last edited on
1
2
3
4
5
// set the floating point output format to fixed a format, 
// and zero digits after the decimal point (the program only outputs whole numbers.)
std::cout << std::fixed << std::setprecision(0) ;

// print out stuff 
Last edited on
Topic archived. No new replies allowed.