for loop with nested decision

I need some pointers again. The program is suppose to be a for loop with nested decision. I'm have a problem with layout and organization. The program will run, but will not do any calculations until the last loop. I'm just not getting how to incorporate the functions.

#include <iostream>
#include <cmath>

using namespace std;

void getdata (int, int, char &, int &, int &, int &);
float HatSize (int, int, int);
int JacketSize (int, int, int);
int WaistSize (int);


int main (void)
{
char clothcode ;
int weight, heightft, heightin, J, W ;
float H ;
int count, i ;

getdata (count, i, clothcode, weight, heightft, heightin);
H = HatSize (weight, heightft, heightin);
J = JacketSize (heightft, heightin, weight);
W = WaistSize (weight);

if (clothcode == 'H')
{
cout << "Hat Size = " << H << endl;
}
else if (clothcode == 'J')
{
cout << "Jacket Size = " << J << endl;
}
else if (clothcode == 'W')
{
cout << "Waist Size = " << W << endl;
}
else
{
cout << "Invalid Clothing Code" << endl;
}

system ("pause");
return 0;

}
void getdata (int i, int count, char & clothcode, int & weight, int & heightft, int & heightin)
{

cout << "This program will calculate clothing sizes.\n" ;
cout << "Enter how many times this program will execute:" ;
cin >> i ;
count = 0;
count = count + i;
for (count = 0; count < i; count++)
{
cout << "Clothing Codes\n" ;
cout << "Hat = H\n" ;
cout << "Jacket = J\n" ;
cout << "Waist = W\n" ;
cout << "Enter clothing code: " ;
cin >> clothcode ;

cout << "Enter weight\n" ;
cin >> weight ;
cout << "Enter height in feet followed by inches\n" ;
cout << "Feet: " ;
cin >> heightft ;
cout << "Inches: " ;
cin >> heightin ;
}
}

float HatSize (int weight, int heightft, int heightin )
{
return (2.9 * ( weight / ( heightft * 12 + heightin ))) ;
}

int JacketSize (int heightft, int heightin, int weight )
{
return ((( heightft * 12 + heightin ) * weight ) / 288 ) ;
}
int WaistSize (int weight)
{
return (weight / 4.9);
}
Last edited on
in get data, every time it loops it changes the values that are being "returned" by reference parameter. You should instead only do it once, and have a loop in main.
//Thanks Gumbercules I get it, here is my progress.

#include <iostream>
#include <cmath>

using namespace std;

void getdata (int, int, char &, int &, int &, int &);
float HatSize (int, int, int);
int JacketSize (int, int, int);
int WaistSize (int);


int main (void)
{
char clothcode ;
int weight, heightft, heightin, J, W ;
float H ;
int count, i ;


cout << "This program will calculate clothing sizes.\n" ;
cout << "Enter how many times this program will execute:" ;
cin >> i ;
count = 0;
count = count + i;
for (count = 0; count < i; count++)
{

getdata (count, i, clothcode, weight, heightft, heightin);
H = HatSize (weight, heightft, heightin);
J = JacketSize (heightft, heightin, weight);
W = WaistSize (weight);

if (clothcode == 'H')
{
cout << "Hat Size = " << H << endl;
}
else if (clothcode == 'J')
{
cout << "Jacket Size = " << J << endl;
}
else if (clothcode == 'W')
{
cout << "Waist Size = " << W << endl;
}
else
{
cout << "Invalid Clothing Code" << endl;
}

}

system ("pause");
return 0;

}
void getdata (int i, int count, char & clothcode, int & weight, int & heightft, int & heightin)
{

cout << "Clothing Codes\n" ;
cout << "Hat = H\n" ;
cout << "Jacket = J\n" ;
cout << "Waist = W\n" ;
cout << "Enter clothing code: " ;
cin >> clothcode ;

cout << "Enter weight\n" ;
cin >> weight ;
cout << "Enter height in feet followed by inches\n" ;
cout << "Feet: " ;
cin >> heightft ;
cout << "Inches: " ;
cin >> heightin ;
}

float HatSize (int weight, int heightft, int heightin )
{
return (2.9 * ( weight / ( heightft * 12 + heightin ))) ;
}

int JacketSize (int heightft, int heightin, int weight )
{
return ((( heightft * 12 + heightin ) * weight ) / 288 ) ;
}
int WaistSize (int weight)
{
return (weight / 4.9);
}



Last edited on
Topic archived. No new replies allowed.