90 142
Assignments Done
99.4%
Successfully Done
In September 2020

# 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 &lt;iostream&gt;
#include &lt;iomanip&gt;
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&lt;=3;numStores+=1)
{
cout &lt;&lt; &quot;Store&quot; &lt;&lt; numStores &lt;&lt; &quot;payroll:&quot;;
cin &gt;&gt; storePayroll;
totalPayroll+=storePayroll;
} //end for

//begin if statement
if (totalPayroll&gt;=60,000)
{
totalPayroll=totalPayroll*RATE;
}
else
cout &lt;&lt; &quot;totalPayroll: $&quot; &lt;&lt; totalPayroll &lt;&lt; endl; //end if system(&quot;pause&quot;); 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!