ok here is the whole code I have written.....this wont work for the commented out parts:
Code:cin >> jobnum; while (!cin.eof()) { cin >> code; while(code!='Q') { if (code == 'P') { cin >> num; for (int i=1; i <= num; i++); { cin >> size; if (size == 'S') { total1 = total1 + S; } else if (size == 'M') { total1 = total1 + M; } else if (size == 'L') { total1 = total1 + L; } } } else if (code == 'R') { cin >> num; total2 = total2 + (num* REMOVAL); } else if (code == 'T') { cin >> trimnum; total3 = total3 + (trimnum * TRIM); } /* else if (code == 'S') *this wont work when uncommented...stays in infinite loop { cin >> num; for (int j =1; j <= num; j++) { cin >> diam; if (diam <=10) { total4 = total4 + 75; } else if (diam > 10) { total4 = total4 + (diam * 10); } } } */ cin >> code; } sum1 = total1 + total2 + total3 + total4; cout << jobnum << " $" << right << setw(7) << total1 << " $" << setw(8) << total2 << " $" << setw(8) << total3 << " $" << setw(10) << total4 << " $" << setw(10) \ << sum1 << endl; total1 = 0.0; total2 = 0.0; total3 = 0.0; total4 = 0.0; cin >> jobnum; } cout << "TOTAL" << setw (65) << sum << endl; ////////need to fix this }
So: no you didn't remove the semicolon. You should do so.
The problem with your S loop is that it's finding your S for a size, and the reading gets out of whack. It's still not an infinite loop though, since num must have a value even if you read it in.
I cant BELIEVE it was that tiny little thing!!!!!! THANK YOU!!!!!!!!!!!!!!!!! It works now!
so what do i need to do for the S loop...i see what your saying...but i dont know what to do to fix it...i ran through it by hand...and it worked...but I am also not a computer... thanks!
for the S input...it will read te first number which tells it how many sizes it need to read in.
So for S 5 12 3 10 7 16
it reads in num which is 5.
it should go through the for loop 5 times...reading in the diameters after it.....
There's nothing wrong with your S loop.
The condition after the else is redundant, but it still works.
ok well your right it works now...i dont know if removing the semicolon made it work but it does.
i now have to add all of the sum's to get a final total...any suggestions?
Job# Planting Removal Trimming Removal Billed
123 $ 235 $ 0 $ 187.5 $ 0 $ 422.5
456 $ 500 $ 2000 $ 0 $ 505 $ 3005
TOTAL 0 <--- this is where i need to add the 422.5 and the 3005.
I got it...nevermind thanks so much!!!
Keep a running total that you don't zero out at the start of every new job.