Look over this assignment for errors and help point them out

If you could read this and help point out the errors and how to fix em I would appreciate it. I can honestly say I've learned a lot on these forums and continue to from everyone's input. ( a few weeks ago I could barely do anything in C++)

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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

//Definition of Function

double calc(int cargoAmount, double pricePerUnit)
{
	return cargoAmount * pricePerUnit;
}

//Void Function description. Sales Amount and Cost in Column Format
void printOutput();
//Definition of this void function
void printOutput()
{
}

int main() {

	//Constant Variables
	const double FUEL_POD = 125.50;
	const double PROTON_AMMO = 17.2;
	const double JET_PACK = 99.00;
	const double OXYGEN= 50.40;

cout << "Welcome to .....\n\n" << endl;

	//Integers hold values entered by user 

        int shipid = 0;
	int nbrFuelPods;
	int nbrCannonAmmo;  // requires math for every 100 rounds
	int nbrJetpacks;
	int nbrOxy;

	//Double variables to hold cost of items

	double costFuelPods;
	double costAmmo;
	double costJetpack;
	double costOxygen;
	double totalCost;
	
	costFuelPods = calc(nbrFuelPods, FUEL_POD);
	costAmmo = calc(nbrCannonAmmo / 100, PROTON_AMMO);

	totalCost = costFuelPods + costAmmo;

	//String variable to hold name of captain. 
	string captName;

	//REPEAT UNTIL ID equals -999

	while ((std::cout << "Please Enter Spaceship Identification or -999 to Terminate  ") && (std::cin >> shipid) && (shipid != -999))
	
	{
		cin.ignore();
		cout << "Please Enter the Captain’s Name: "; //Prompt to enter Captain Name
		getline(cin, captName); //Enter Name 
		cout << "Please Enter Fuel Pod Sales: ";
		cin >> nbrFuelPods;   //Enter Pods
		cout << "Please Enter Proton Cannon Ammunition Sales: ";
		cin >> nbrCannonAmmo;  //Enter Ammo
		cout << "Please Enter Jetpack Sales: ";
		cin >> nbrJetpacks; //Enter Jetpacks
		cout << "Please Enter Oxygen Sales: ";
		cin >> nbrOxy; //Enter Oxy sales

		//Top Display 
		/* Show  title,  cpt's Name, ID & bottom border */
		cout << endl;
		cout << endl;
		cout << left << "The .............." << endl;
		cout << "Spaceship ID Number " << shipid << endl;
		cout << "  Captain's Name:" << setw(3) << captName << endl;
		cout << "  *********************************" << endl;

	//costs	
		costFuelPods = nbrFuelPods * FUEL_POD;
		costAmmo = (nbrCannonAmmo / 100) * PROTON_AMMO; 
		costJetpack = nbrJetpacks * JET_PACK;
		costOxygen = nbrOxy * OXYGEN;
		totalCost = (costFuelPods + costAmmo + costJetpack + costOxygen);

		cout << setw(15) << "Cargo " << setw(20) << "Sales Amount " << setw(20) << "Cost" << endl;
		cout << setw(15) << "Fuel Pod " << setw(20) << nbrFuelPods << fixed << setprecision(2) << "$" << costFuelPods << endl;
		cout << setw(15) << "Proton Cannon Ammunition " << setw(20) << nbrCannonAmmo << fixed << setprecision(2) << "$" << costAmmo << endl;
		cout << setw(15) << "JetPack " << setw(20) << nbrJetpacks << fixed << setprecision(2) << "$" << costJetpack << endl;
		cout << setw(15) << "Oxygen " << setw(20) << nbrOxy << fixed << setprecision(2) << "$" << costOxygen << endl;
		cout << "---------------------------------------------\n";
		cout << "=======================================================" << endl;
		cout << "\n\n";
		cout << setw(35) << "Total Due: " << fixed << setprecision(2) << "$" << totalCost << endl;
		cout << endl;
		}
	system("Pause");
	return 0;                    }
Last edited on
Line 4: bad practice (google it)
Line 6: this comment is only useful to someone inexperienced with C++ - comments should explain why, not what
Line 9: not sure what you're worried about
Line 14: unusual comment
Line 15: Why declare the function and then define it two lines later? Remove this line.
Line 16: same issue as line 6
Lines 18-19: empty function body, probably not intended
Lines 20-23: you already made this function on line 7, now you've just duplicated it with a different name
Line 24: inconsistent brace style (you usually have braces on their own line)
Line 26: same issue as line 6
Lines 27-30: if these are the costs, you probably want to have "COST" in the names
Line 32: unusual indentation
Line 34: same issue as line 6
Line 36: unusual indentation
Line 38: the comment is useful but has strange wording
Line 42: same issue as line 6
Lines 44-48: variables declared long before they are ever given values (don't declare a variable until you are going to give it a value)
Line 50: use of uninitialized variable nbrFuelPods - you probably want to remove this line
Line 51: same issue as line 50
Line 53: same issue as line 50
Line 55: same issue as line 6
Line 58: same issue as line 6
Line 61: unusual blank line, remove it for consistency
Lines 64, 65, 67, 69, 71, 73: same issue as line 6
Line 76: inconsistent style; also possibly same issue as line 6
Lines 77-78: could be collapsed to one line
Line 84: inconsistent indentation
Lines 85-88: I think you're supposed to use your calcCost function?
Line 89: variable should be declared here instead of on line 48 (ditto for previous lines)
Line 101: unusual indentation
Line 103: inconsistent brace style (you usually have braces on their own line)
Thanks
Last edited on
Oh, you edited your post while I was typing mine. A lot of line numbers are offset.
Topic archived. No new replies allowed.