Here's what I have so far.....I still can't figure out what I'm doing wrong. I've been working on this problem for a week now. Very new to C++ :
#include<iostream.h>
main(){
int numberofemployees;
int employeeid, hoursworked;
float hourlyrate,grosspay,taxamount,netpay;
const float TAXRATE = 0.10;
it counter = 0;
cout<<"Please enter the number of employees:";
cin>>n;
while(counter < n){
cout<<"ENTER THE EMPLOYEE ID:";
cin>>employeeid;
cout<<"ENTER THE HOURS WORKED:";
cin>>hoursworked;
cout<<"ENTER THE HOURLY RATE:";
cin>>hourlyrate;
grosspay=hoursworked*hourlyrate;
taxamount=grosspay*TAXRATE;
netpay=grosspay-taxamount;
cout<<"THE HOURS WORKED ARE "<<hoursworked<<endl;
cout<<"THE GROSSPAY IS "<<grosspay<<endl;
cout<<"THE TAX AMOUNT IS "<<taxamount<<endl;
cout<<"THE NETPAY IS "<<netpay<<endl;
}//WHILE
system("PAUSE");
return 0;
#include<iostream.h>
int main()
{
int numberofemployees;
int employeeid, hoursworked;
float hourlyrate,grosspay,taxamount,netpay;
constfloat TAXRATE = 0.10;
int counter = 0;
cout<<"Please enter the number of employees:";
cin>>n;
while(counter < n)
{
cout<<"ENTER THE EMPLOYEE ID:";
cin>>employeeid;
cout<<"ENTER THE HOURS WORKED:";
cin>>hoursworked;
cout<<"ENTER THE HOURLY RATE:";
cin>>hourlyrate;
grosspay=hoursworked*hourlyrate;
taxamount=grosspay*TAXRATE;
netpay=grosspay-taxamount;
cout<<"THE HOURS WORKED ARE "<<hoursworked<<endl;
cout<<"THE GROSSPAY IS "<<grosspay<<endl;
cout<<"THE TAX AMOUNT IS "<<taxamount<<endl;
cout<<"THE NETPAY IS "<<netpay<<endl;
}//WHILE
system("PAUSE");
return 0;
}//MAIN
On line 8, it should be int counter = 0;. Probably just a typo, right?
In your while loop, you have the expression counter<0, but where in the body of the loop do you increment counter? If counter starts at 0 and never changes value, it will always be less than the value of "n", and your while loop is infinite.
I'm sorry I just don't understand I've only been programming for two weeks now and this is all new to me. This is what I have now and it still isn't executing, what am I doing wrong???
#include<iostream.h>
int main()
{
int numberofemployees;
int employeeid, hoursworked;
float hourlyrate,grosspay,taxamount,netpay;
const float TAXRATE = 0.10;
int counter = 0;
cout<<"Please enter the number of employees:";
cin>>n;
while(counter < n)
{
cout<<"ENTER THE EMPLOYEE ID:";
cin>>employeeid;
cout<<"ENTER THE HOURS WORKED:";
cin>>hoursworked;
cout<<"ENTER THE HOURLY RATE:";
cin>>hourlyrate;
grosspay=hoursworked*hourlyrate;
taxamount=grosspay*TAXRATE;
netpay=grosspay-taxamount;
cout<<"THE HOURS WORKED ARE "<<hoursworked<<endl;
cout<<"THE GROSSPAY IS "<<grosspay<<endl;
cout<<"THE TAX AMOUNT IS "<<taxamount<<endl;
cout<<"THE NETPAY IS "<<netpay<<endl;
}//WHILE
system("PAUSE");
return 0;
}//MAIN
Basically, you need to add a line of code to the body of the while loop that increases the value of counter at the end of each iteration. After 1 iteration, counter =1, after the next one, counter =2, and so on.
There are several ways to do this, but the most common way is ++variable.
EDIT: You also forgot to declare the variable "n"
EDIT: iostream.h has been depricated for a while now. Try using <iostream> instead and add the line usingnamespace std; underneath it.
I'm completely lost. Is there any way you can show me how a finished product looks like that actually executes so I can see where I made my mistakes and compare?
You declare int numberofemployees; but you don't use it. From the variable name, I assume you intended to use it as the value to which int counter; is compared.
You don't declare "n", but you use it as the value to which int counter; is compared.
Do you see now? You need to decide whether to use "numberofemployees" or "n" as the variable, declare it, and use it in the test expression of the while loop
#include <iostream>
usingnamespace std;
int main()
{
string employeeid; // the reason i changed this to a string is if you ever want to do string comparisons with employeeids.
int hoursworked;
float hourlyrate,grosspay,taxamount,netpay;
float TAXRATE = 0.10;
int counter = 0;
int n; // number of employees.
cout<<"Please enter the number of employees:";
cin>>n;
while(counter < n)
{
cout<<"ENTER THE EMPLOYEE ID:";
cin>>employeeid;
cout<<"ENTER THE HOURS WORKED:";
cin>>hoursworked;
cout<<"ENTER THE HOURLY RATE:";
cin>>hourlyrate;
grosspay=hoursworked*hourlyrate;
taxamount=grosspay*TAXRATE;
netpay=grosspay-taxamount;
cout<<"THE HOURS WORKED ARE "<<hoursworked<<"\n";
cout<<"THE GROSSPAY IS "<<grosspay<<"\n";
cout<<"THE TAX AMOUNT IS "<<taxamount<<"\n";
cout<<"THE NETPAY IS "<<netpay<<"\n";
++counter;
}//WHILE
cin.ignore();
cin.get();//same as sytem pause but takes less resources and better code.
return 0;
}//MAIN
what ide are you using most will tell you when you have undeclared & unused variables?
code::blocks is a good one to use.
This is the next part of the problem. I'm gonna try and do it myself but feel free to contribute if you have any tips for me. Once this part is done my assignment is totally finished.