Debugging (Please help!)

#include <iostream>
using namespace std;

int main()
{
int sales = 0;
int totalSales = 0;
for (int store = 1, store < 3, store = store + 1)
{
cout << "First sales amount for store " << store
<< " (negative number to stop): ";
cin >> sales;
do
{
totalSales = totalSales + sales;
cout << "Next sales amount for store " << store
<< " (negative number to stop): ";
cin >> sales;
} while (sales >= 0)
cout << endl;
}
cout << "Total: $" << totalSales << endl;
return 0;
}
Last edited on
1. Code tags?
2. What's wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main()
{
  int sales = 0;
  int totalSales = 0;
  for (int store = 1; store < 3; store = store + 1)
  {
      cout << "First sales amount for store " << store
       << " (negative number to stop): ";
      cin >> sales;
      while ( sales >= 0 )
     {
        totalSales = totalSales + sales;
        cout << "Next sales amount for store " << store
         << " (negative number to stop): ";
         cin >> sales;
     }
     cout << endl;
}
cout << "Total: $" << totalSales << endl;
return 0;
}


In case you wish to stick to do while loop, then there should be a semicolon after the while condition.

EDIT: Changed comma's to semicolons in the for loop declaration
Last edited on
abhishekm71 (413)
Thank You!
Topic archived. No new replies allowed.