Hi, i am trying to make a BMI calulator and here is my code:
#include<iostream>
#include<sstream>
#include<fstream.h>
using namespace std;
int main (char argc)
{
double ff1;
double ii1;
double ww1;
for(;;)
{
system("cls");
cout << "Enter feet." << endl;
string f1;
cin >> f1;
stringstream(f1) >> ff1;
if(ff1 >! -999999999) // I wanted to use if(stringstream(f1).fail()) but that didnt work
{
if(f1 == "u")
{
fstream feet;
feet.open("feet.txt");
feet >> ff1;
}
if(f1 == "uc")
{
fstream feet1;
feet1.open("feet.txt");
cout << "Enter new default feet." << endl;
double f2;
cin >> f2;
feet1 << f2;
ff1 = f2;
}
}
else
{
stringstream(f1) >> ff1;
}
cout << ff1 << endl;
cout << "Enter inches." << endl;
string i1;
cin >> i1;
stringstream(i1) >> ii1;
if(ii1 >! -999999999)
{
if(f1 == "u")
{
fstream inches;
inches.open("inches.txt");
inches >> ii1;
}
if(f1 == "uc")
{
fstream inches1;
inches1.open("inches.txt");
cout << "Enter new default inches." << endl;
double i2;
cin >> i2;
inches1 << i2;
ii1 = i2;
}
}
else
{
stringstream(i1) >> ii1;
}
cout << "Enter weight." << endl;
string w1;
cin >> w1;
stringstream(w1) >> ww1;
if(ww1 >! -999999999)
{
if(f1 == "u")
{
fstream weight;
weight.open("weight.txt");
weight >> ii1;
}
if(f1 == "uc")
{
fstream weight1;
weight1.open("weight.txt");
cout << "Enter new default weight." << endl;
double w2;
cin >> w2;
weight1 << w2;
ww1 = w2;
}
}
else
{
stringstream(w1) >> ww1;
}
ff1 = ff1 * 12;
ff1 = ff1 + ii1;
ff1 = ff1 * ff1;
ww1 = ww1 * 703;
double bmi = ww1 / ff1;
cout << "Your BMI is " <<bmi<< endl;
system("pause");
}
}
Whenever i enter u or uc as the feet, inches, or weight, the program doesnt run that loop. Also, i dont think that the program is reading the text files. Any solutions?