The loop works fine if I do not have the if
statement, but once I add it in, the code no longer runs. It doesn't have a problem when building. I can tell that I didn't initialize repNum
when I run it.
The code as follow:
#include<iostream>
using namespace std;
int main()
{
int repNum;
int prodSold;
int prodPrice;
int repTotal;
int numReps = 0;
if (repNum >0 && repNum < 21)
{
for(int numReps = 0; numReps <= 20; numReps ++)
{
cin >> repNum;
cin >> prodSold;
cin >> prodPrice;
repTotal = prodSold * prodPrice;
cout << "Agent #" << repNum << " sold " << prodSold << " packages at $" << prodPrice <<
" for a dollar value of $" << repTotal << endl;
}
}
else
{
cout << "***Invalid Agent***" << endl;
}
}