do while loop

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?

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
#include <cmath>
#include <iomanip>
#include <iostream>

using namespace 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;
}
	
Last edited on
- Delete lines 1, 2, 22 and 23.
- Line 67: y and Y are characters so must be 'y' and 'Y'.
- Why braces in lines 65 and 72? Delete those lines.
Last edited on
Topic archived. No new replies allowed.