i'm trying to write a program that takes information about a vehicle's engine, such as inch displacement, max rpm, and volumetric efficiency, and output the engine's max cfm, or what size carburetor to use.
the code seems to work fine other than one variable, "veff". it seems to have trouble multiplying by "veff". at first i had called it "ve" and changed to veff because i thought maybe it didn't like 2-char variable names? but the problem didn't stop.
i usually get some sort of scientific formatted number. for example with the first function, cfm. i input 7000 rpm, 355 inches, and .95 volumetric efficiency. the cfm output should be around 685, but the output is "6.8e+002".
i have tried breaking the formulas down piece by piece and it always seems to be when i add the veff to it that it messes up. i've also tried playing with parentheses around different stuff, to no avail. thanks in advance for the help.
-marcus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char **argv)
{
float cfm();
float rpm();
float disp();
float veff();
int selection;
char yn;
choose:
cout << "What would you like me to find? \n 1. Engine CFM \n
2. Engine RPM \n 3. Engine Displacement \n 4. Volumetric
Efficiency" << endl;
cin >> selection;
if (selection<1||selection>4)
{
cout << "type 1-4 for choice";
goto choose;
}
cout << setprecision(2);
if (selection==1) cout << cfm() << " cfm" << endl;
if (selection==2) cout << rpm() << " rpm" << endl;
if (selection==3) cout << disp() << " cu. inches" << endl;
if (selection==4) cout << veff() << "% VE" << endl;
cout << "Would you like to go again? y/n: ";
cin >> yn;
if (yn=='y'||yn=='Y') goto choose;
return 0;
}
float cfm()
{
float rpm;
float disp;
float veff;
cout << "Engine RPM: ";
cin >> rpm;
cout << "Engine Displacement: ";
cin >> disp;
cout << "Volumetric Efficiency: ";
cin >> veff;
return veff*(disp/1728*(rpm/2));
}
float rpm()
{
float cfm;
float disp;
float veff;
cout << "Engine CFM: ";
cin >> cfm;
cout << "Engine Displacement: ";
cin >> disp;
cout << "Volumetric Efficiency: ";
cin >> veff;
return 2*cfm/veff/(disp/1728);
}
float disp()
{
float cfm;
float rpm;
float veff;
cout << "Engine CFM: ";
cin >> cfm;
cout << "Engine RPM: ";
cin >> rpm;
cout << "Volumetric Efficiency: ";
cin >> veff;
return 1728*cfm/veff/(rpm/2);
}
float veff()
{
float cfm;
float rpm;
float disp;
cout << "Engine CFM: ";
cin >> cfm;
cout << "Engine RPM: ";
cin >> rpm;
cout << "Engine Displacement: ";
cin >> disp;
return 100*cfm/(rpm/2)/(disp/1728);
}
|