I know my do while loop is in the wrong place, but I can't seem to find the right spot for it. It won't let me loop it. Can someone tell me where it should go and why please? Also, is my if else statement correct?
#include <cmath>
#include <iomanip>
#include <iostream>
usingnamespace std;
double findcargomoment (double);
double findcrewmoment (int);
int main()
{
int crewnum;
double cargoweight;
double totalweight;
double gravitycenter;
double fuelmoment =1169167.3;
double emptymoment = 2751405;
double cargomoment;
double crewmoment;
char choice = 'y';
char y = 0;
char Y = 0;
cout <<"This program will calculate the total weight and the center of gravity of a plane with the desired crew size and cargo weight"<<endl<<endl;
cout <<"The empty weight of the plane is 9021 lbs and its center of gravity is 305 in from the nose of the plane"<<endl;
cout <<"The aircraft can hold a maximum of 540 gallons of fuel, and is full at time of take off"<<endl;
cout <<"The weight of fuel is 6.7 lbs per gallon"<<endl;
do{
cout <<endl<<"How many crew members are there? maximum of two."<<endl<<endl;
cin >>crewnum;
cout <<endl<<"What is the weight of the cargo? maximum 5000 lbs."<<endl<<endl;
cin >>cargoweight;
if (cargoweight<=5000.)
{
totalweight = cargoweight + crewnum*160 + (6.7*540) + 9021;
cout <<endl<<"The total weight of the plane is "<<totalweight<<" lbs"<<endl<<endl;
crewmoment = findcrewmoment(crewnum);
cargomoment = findcargomoment(cargoweight);
gravitycenter = (fuelmoment + cargomoment + emptymoment + crewmoment)/totalweight;
cout <<"The center of gravity of the plane is "<<gravitycenter<<" in"<<endl<<endl;
cout <<"Would you like to run this again? y or Y for yes, anything else for no"<<endl<<endl;
cin>>choice;
}
else
{cout <<"The cargo weight must be between 0 and 5000"<<endl<<endl<<endl;
}while (choice == y || choice ==Y);
system ("pause");
return 0;
}
}
double findcargomoment (double cargoweight)
{double cargomoment;
cargomoment = 345*cargoweight;
return cargomoment;
}
double findcrewmoment (int crewnum)
{double crewmoment;
crewmoment = 160*120*crewnum;
return crewmoment;
}