//Lab 5                               Ray Perales 
//This program will compute a user's hat size, jacket size, and waist measurement
// based on a three function modular program.

#include <iostream>
#include <iomanip>
#include <fstream> 
#include <cmath>

// Prototype declarations
double findHatSize (double height, double weight);
double findJacketSize (double height, double weight, int age);
double findWaist (double weight, int age);

using namespace std;

int main()
{   
    ifstream fin;
    fin.open("readLab5.cpp");
    if (fin.fail())
    {
       cerr << "error opening input file. \n\n";
       system("pause");
       exit(1);
    }
    ofstream fout;
    fout.open("outputLab5.out");
    if (fout.fail())
    {
       cerr << "error opening output file.\n\n";
       system("pause");
       exit(1);
    }
    fout.setf(ios::fixed);
    
    int age;
    double height, weight, HatSize, JacketSize, waist;
    fout << "Height: ";
    fout <<setw(7)  <<"Weigtht: ";
    fout <<setw(5)  <<"Age: ";
    fout <<setw(11) <<"Hat size: ";
    fout <<setw(13) <<"Jacket Size: ";
    fout <<setw(9)  <<"Waist: \n";
    
    while (fin >> height >> weight >> age)
    {
    HatSize = findHatSize(height, weight);
    JacketSize = findJacketSize(height, weight, age);
    waist = findWaist(weight, age);
    
    fout.precision(0);
    fout << setw(6) << height;
    fout << setw(6) << weight;
    fout << setw(6) << age;
    fout.precision(4);
    fout << setw(11) << HatSize;
    fout << setw(11) << JacketSize;
    fout << setw(11) << waist << endl;
    }
    
    system("pause");
    return 0;
}

//function definition for hat size.
double findHatSize(double height, double weight)
{
       double hatSize;
       hatSize = (height/weight)*2.90;
       return hatSize;
}
//function definition for jacket size.
double findJacketSize(double height, double weight, int age)
{
       double jacketSize;
       if (age > 30)
          jacketSize = (height * weight / 288) + ((age - 30)/10)* 0.125;
       else
          jacketSize = (height * weight / 288);
       return jacketSize;
}
//function definition for waist size.
double findWaist(double weight, int age)
{
       double waist;
       if (age > 28)
            (weight/ 5.7) + ((age - 28) / 2) * .01;
       else
            waist = (weight/ 5.7);
       return waist; 
} 

/* Input reading int
73 205	20
73 205	55

no output to output file */

Are you sure about the input file's name ??

fin.open("readLab5.cpp");

You almost got the code tags right, however next time you might want to utilize the "Preview Post" button to make sure that the code tags really are right.

double findWaist(double weight, int age) {
	double waist;
	if (age > 28)
		(weight/ 5.7) + ((age - 28) / 2) * .01;
	else
		waist = (weight/ 5.7);
	return waist;
}

after if (age > 28) it must be waist = (weight/ 5.7) + ((age - 28) / 2) * .01;
and fin.open("readLab5.cpp"); - why .cpp

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.