problem is that i cant get my "else" to work. i tryed it with only the if and got it kinda working. after you put your lenght in, it jumps to "what is your name" and the tells if bmi is goo or bad and then to "press any key to continue...."
#include <iostream>
#include <string>
usingnamespace std;
int name, meter, kg;
long bmi;
int main()
{
cout << "vad är din vikt i KG?: "; //whats your weight
cin >> kg;
cout << "Hur lång är du i meter: "; //whats your height in meters
cin >> meter;
cout << "Och slutligen vad är dit namn: "; //and finally whats your name
cin >> name;
bmi = (meter*meter) / kg;
while(true);
{
if (bmi < 35);
{
cout << "not so good";
}
else //"else" getting redlined
{
cout << "great";
}
}
system("pause");
return 0;
}
The problem is on line 27, you put a semicolon after the if statement which is the cause of the error you are experiencing with your else statement. Remove the semicolon at the end of that line and your else statement should work.
#include <iostream>
#include <string>
usingnamespace std;
int name, meter, kg;
long bmi;
int main()
{
cout << "vad är din vikt i KG?: "; //whats your weight
cin >> kg;
cout << "Hur lång är du i meter: "; //whats your height in meters
cin >> meter;
cout << "Och slutligen vad är dit namn: "; //and finally whats your name
cin >> name;
bmi = (meter*meter) / kg;
while(true);
{
if (bmi < 35) //there was a semicolon here causing the error
{
cout << "not so good";
}
else //"else" getting redlined
{
cout << "great";
}
}
system("pause");
return 0;
}
The while loop condition of true is never changed, so there's an infinite loop. Do you need a loop? Are they supposed to be able to input details for multiple people?
Why declare global variables at lines 6 and 7 instead of declaring them locally in the main function?