Sentinel Controlled Loop

I am trying to write a program in Visual C++ 2008 Express Edition that accepts sales amounts input from the keyboard and counts the sales that are at or above the target amount or below the target amount. I am getting an error when trying to debug. I have to set a target amount. This is what I have:

#include <iostream>
using namespace std;

const float targetAmount = 45.00;
const int sentinel = 0;

int main()
{
int salesAtOrAboveTA, salesBelowTA, Count; // Declare variables as integer
float salesAmount; // Declare variable as float
salesAmount = 0; // Initialize loop variable
Count = 0;

cin >> salesAmount;
while (salesAmount != sentinel)
{
Count++;
cin >> salesAmount;
}
if (salesAmount >= targetAmount)
{
cout << "Number of sales at or above target: " << salesAtOrAboveTA << endl;
}
else
cout << "Number of sales below target: " << salesBelowTA << endl;

return 0;
}
Let me guess. You enter an infinite loop.

http://www.cplusplus.com/forum/articles/6046/
I don't see the infinite loop, but you're trying to cout salesAtOrAboveTa and salesBelowTa without initializing them. You only declare them:

int salesAtOrAboveTA, salesBelowTA,
I actually did not get to the debugging stage. When I try to rebuild I get these error messages:

warning C4700: uninitialized local variable 'salesAtOrAboveTA' used
warning C4700: uninitialized local variable 'salesBelowTA' used

Should I have set these variables equal to zero before my 'while' statement?
Those variables are what I'm referring to. In the below lines, you are attempting to output the variables that have no values:

1
2
cout << "Number of sales at or above target: " << salesAtOrAboveTA << endl;
cout << "Number of sales below target: " << salesBelowTA << endl;


They need some sort of value. Just initialize them to 0 until you put them to use.
Thanks for all of the feedback. Initializing them to 0 got rid of the errors.
Topic archived. No new replies allowed.