I have an assignment where I'm supposed to take an old code and rewrite it using functions. I'm still a little shady on where I'm supposed to include certain parts of information. Could someone take a look at them and see where I misplaced the information? I'm brand new to this so please don't assume this is sloppy work because I'm lazy. This is my original code:
Code:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
// Declare and initialize variables and constants
//(r = radius, g = acceleration due to gravity,
// ds = solid density, df = fluid density,
// fv = fluid viscosity, v = velocity, t = time,
// d = distance to bottom of tank.)
double r, g, d, ds, df, fv, v, t, df1, ds1, fv1;
//**Print values**//
//Constants
cout << "Distance to bottom of tank = 20.0 cm" << endl;
cout << "Radius of the particle = 0.5 cm" << endl;
cout << "Local value of g (gravity) = 980.00 cm/s^2" << endl;
//User inputs
cout << endl;
cout << "Please enter a value for the fluid density (g/cm^3): ";
cin >> df;
cout << "The value you entered is " << df << endl;
df1=df;
cout << endl;
cout << "Please enter a value for the solid density (g/cm^3): ";
cin >> ds;
cout << "The value you entered is " << ds << endl;
ds1=ds;
cout << endl;
cout << "Please enter a value for the fluid viscosity (g/cm-s): ";
cin >> fv;
cout << "The value you entered is " << fv << endl;
fv1=fv;
r=0.5, g=981, d=20;
v = ((2.0/9)*((ds1-df1)/fv1)*g*r*r)/100;
t = (d/v);
//Calculations
cout << endl;
cout << fixed << setprecision(2);
cout << "Fluid density: " << setw (10) << df << " g/cm^3" << endl;
cout << "Solid density: " << setw (10) << ds << " g/cm^3" << endl;
cout << "Fluid viscosity: " << setw (8) << fv << " g/cm-s" << endl;
cout << "Velocity: " << setw(15) << v << " cm/s" << endl;
cout << "Falling time: " << setw (11) << t << " s" << endl;
return 0;
}
and this is the one I'm trying to create using functions:
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
//Constants
void printInformation ()
{
cout << "Distance to bottom of tank = 20.0 cm" << endl;
cout << "Radius of the particle = 0.5 cm" << endl;
cout << "Local value of g (gravity) = 980.00 cm/s^2" << endl;
}
// Declare and initialize variables and constants
//(r = radius, g = acceleration due to gravity,
// ds = solid density, df = fluid density,
// fv = fluid viscosity, v = velocity, t = time,
// d = distance to bottom of tank.)
void calculateVelocityAndTime(double r, double g, double d, double df,
double ds, double fv, double& v, double& t)
{ v = ((2.0/9)*((ds-df)/fv)*g*r*r)/100;
t = (d/v);
cout << endl;
cout << fixed << setprecision(2);
cout << "Fluid density: " << setw (10) << df << " g/cm^3" << endl;
cout << "Solid density: " << setw (10) << ds << " g/cm^3" << endl;
cout << "Fluid viscosity: " << setw (8) << fv << " g/cm-s" << endl;
cout << "Velocity: " << setw(15) << v << " cm/s" << endl;
cout << "Falling time: " << setw (11) << t << " s" << endl;
}
void displayResults(double dp, double mu, double r,
double H, double Ho, double velocity, double time);
int main()
{
printInformation();
cin << df << endl;
cin << ds << endl;
cin << fv << endl;
displayesults();
cout << v << " " << t << endl;
return 0;
}