Hey can you help me fix this function, my lab partner wrote our last lab and messes this function up and i have no idea how to fix it, he just gave me the program to work on and its due in 4 hours, can you set me in the right direction on how to fix it or spot our error?
Edit: Ive narrowed the problem down to the for loop with all the if statements inside of it.
Edit: heres the who program my lab partner has messed up something bad and i cant find it. dropbox.com/s/wgylnriy6vgnkay/Lab10.zip
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
|
void calculateTotals(int mtype, int numItems, int *type, float *cost, float *hours, float *price)
{
string horizontalLine(65, '-');
string canType;
float totalCost = 0;
float totalHour = 0;
float totalPrice = 0;
if (mtype == 2)
canType = "Hard Candy";
else if (mtype == 3)
canType = "Jelly Beans";
else if (mtype == 4)
canType = "Chocolate";
else if (mtype == 5)
canType = "Candy in Inventory";
cout << endl << horizontalLine << "\n\nTotal Pieces Of " << canType << ": \n\n";
cout << setw(13) << left << "TYPE" << right << setw(13) << "MATERIALS COST" << setw(16) << "LABOR HOURS" << setw(16) << "ASKING PRICE" << endl;
//added @Ben Voigt's code so its "cleaner to debug"
if (mtype >= 2 && mtype <= 5) {
for (int itemno = 0; itemno < 1; itemno++) {
if (mtype == type[itemno]) {
price[itemno] = calculatePrice(cost[itemno], hours[itemno]);
totalCost += cost[itemno];
totalHour += hours[itemno];
totalPrice += price[itemno];
if (mtype == 2) cout << setw(13) << left << canType;
cout << setw(13) << right << cost[itemno]
<< setw(16) << setprecision(2) << fixed << hours[itemno]
<< setw(16) << price[itemno] << "\n\n";
if (mtype == 3) cout << setw(13) << left << canType;
cout << setw(13) << right << cost[itemno]
<< setw(16) << setprecision(2) << fixed << hours[itemno]
<< setw(16) << price[itemno] << "\n\n";
if (mtype == 4) cout << setw(13) << left << canType;
cout << setw(13) << right << cost[itemno]
<< setw(16) << setprecision(2) << fixed << hours[itemno]
<< setw(16) << price[itemno] << "\n\n";
if (mtype == 5) cout << setw(13) << left << canType;
cout << setw(13) << right << cost[itemno]
<< setw(16) << setprecision(2) << fixed << hours[itemno]
<< setw(16) << price[itemno] << "\n\n";
}
}
}
cout << "\n" << setw(9) << left << "TOTALS: "
<< setw(5) << right << "$" << setw(12) << totalCost
<< setw(17) << totalHour
<< setw(11) << "$" << setw(5) << totalPrice << "\n\n";
cout << horizontalLine << "\n\n";
cout << flush;
}
|
heres what its supposed to do, I believe the issue is with the for loop he used to keep the running total of how much candy is added to the list, what ours does when we run it is adds 4 more peice than its supposed to.
FUNCTION: calculateTotals
Function Prototype: void calculateTotals(int, int, int[], float[], float[], float[]);
Function Purpose: This function is called when the user wants to view how many items are
in the different Candy types or all together and see how much in total the materials cost
and asking price is for inventory items. There are quite a few parameters accepted in this
function. First, an integer representing what kind of table will be printed out (1=hard
candy, 2=jelly beans, 3=chocolates, -1 = all). Then, an integer representing how many
total items are in the arrays. Then all four arrays that were defined in main.
This function will figure out what type of table the user is wanting based on the first integer
that is passed into the function and print out the respective table name. For example, if the
user wants to print out information on Hard Candy, the header should read “Total Pieces
Hard Candy:”.
Then, the function will print out the table headers. There should be four columns and each
column should have a header (words) at the top of the column explaining what that column
is.
The values should be printed underneath the column headers. The values for total material
cost and total asking price have to be calculated as running totals. To calculate the total
asking price, this function should call the calculatePrice() function.
If the user wants the totals for Hard Candy only, then your program should be able to
figure out if an item is a piece of hard candy and if it is, then print out the hard candy
information in the table.