Hi all
I need assistance with the below code snippit. It calculates how many of salaries entered exceeds R100 000 or how many is below. With the below entries the lower count totals to 4 instead of 5. What am I doing wrong? Still new to this so please excude if the code is everywhere.
Entries:
Enter a yearly salary: R1000
Are there any more values to be input? ('Y' or 'N') y
Enter a yearly salary: R2000
Are there any more values to be input? ('Y' or 'N') y
Enter a yearly salary: R3000
Are there any more values to be input? ('Y' or 'N') y
Enter a yearly salary: R150000
Are there any more values to be input? ('Y' or 'N') y
Enter a yearly salary: R300000
Are there any more values to be input? ('Y' or 'N') n
There are 4 salaries that do not exceed R100 000.
There are 2 salaries that exceeds R100 000.
#include <iostream>
using namespace std;
int main()
{
int count, lcount;
float yearlySalary, totalSalary = 0, totalSalaryB = 0, grandTotal;
const int LIMIT = 100000;
char answer;
count = 0;
lcount = 0;
cout << "Enter a yearly salary: R";
cin >> yearlySalary;
cout << "Are there any more values to be input? ('Y' or 'N') ";
cin >> answer;
do
{
cout << "Enter a yearly salary: R";
cin >> yearlySalary;
if (yearlySalary > LIMIT)
{
totalSalary += yearlySalary;
count++;
}
else if (yearlySalary <= LIMIT)
totalSalaryB += yearlySalary;
lcount++;
cout << "Are there any more values to be input? ('Y' or 'N') ";
cin >> answer;
} while (answer == 'Y' || answer == 'y');
cout << "There are " << lcount << " salaries that do not exceed R100 000." << endl;
cout << "There are " << count << " salaries that exceeds R100 000." << endl;
return 0;
}