Answer to Question #12360 in C++ for Mindy Smith

Question #12360
I am trying to get my if statement to work with the 5% bonus rate, but it is not working. What am I doing wrong?

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
//declare variables
int storePayroll=0;
const double RATE=.05;
int numStores=0;
int totalPayroll=0;

//start for loop
for (int numStores=1;numStores<=3;numStores+=1)
{
cout << "Store" << numStores << "payroll:";
cin >> storePayroll;
totalPayroll+=storePayroll;
} //end for

//begin if statement
if (totalPayroll>=60,000)
{
totalPayroll=totalPayroll*RATE;
}
else
cout << "totalPayroll: $" << totalPayroll << endl;
//end if

system("pause");
return 0;
} //end of main function
1
Expert's answer
2012-07-27T07:22:02-0400
Here is your corrected code. The error was that numStores variable was declared twice - once at the beginning of main block and once in the for loop statement.

#include <iostream>
#include <iomanip>
using namespace std;
&
int main()
{
//declare variables
int storePayroll=0;
const double RATE=.05;
int numStores=0;
int totalPayroll=0;
&
//start for loop
for (numStores=1;numStores<=3;numStores+=1)
{
cout << "Store" << numStores << "payroll:";
cin >> storePayroll;
totalPayroll+=storePayroll;
} //end for
&
//begin if statement
if (totalPayroll>=60,000)
totalPayroll=totalPayroll*RATE;
else
cout << "totalPayroll: $" << totalPayroll << endl;
//end if
&
system("pause");
return 0;
} //end of main function

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS