Question:
C++ Question on Integers?
James
2011-10-29 09:32:09 UTC
Any help would be greatly appreciated.

Assume the input data is structured as follows: first there is a non-negative integer specifying the number of employee time sheets to be read in. This is followed by data for each of the employees. The first number for each employee is an integer that specifies their pay per hour in cents. Following this are 5 integers, the number of hours they worked on each of the days of the workweek. Given this data, and given that an int variable total has been declared, write a loop and any necessary code that reads the data and stores the total payroll of all employees in total . Note that you will have to add up the numbers worked by each employee and multiply that by that particular employee's pay rate to get the employee's pay for the week-- and sum those values into total.

This is what I have managed to put together, I would really appreciate any help in completing this program.

These are the errors I'm getting back.
CTest.cpp: In function 'int main()':
CTest.cpp:17: error: conflicting declaration 'double total'
CTest.cpp:10: error: 'total' has a previous declaration as 'int total'

#include
#include
#include

#include

using namespace std;

int numberOfEmployees;//to store number of employes

double payPerHour;//to store hourly pay

int hoursWorked;//to store worked hours of week

double total=0;//to store total of all employees

//prompting for input number of employees

cout<<"Enter Number of employees : ";

//Reading number of employees

cin>>numberOfEmployees;

//validating number of employees

while(numberOfEmployees<0)

{

cout<<"Invalid entry, Try again"<
cout<<"Enter Number of employees : ";

cin>>numberOfEmployees;

}

int hours;

//reading pay rate for each employee

for(int i=1;i<=numberOfEmployees;i++)

{

hoursWorked = 0;

cin>>payPerHour;

//reading working hours for a week

for(int j=1;j<=5;j++)

{

//reading hours

cin>>hours;

//adding to weekly hours

hoursWorked +=hours;

}

//calculating total salary of all employeess

total +=hoursWorked*payPerHour;

}
Four answers:
oops
2011-10-29 10:05:17 UTC
This code did not produce that error. Please show your actual code and your actual errors. Where's your main function?
anonymous
2011-10-29 15:38:42 UTC
The question has the comment, "and given that an int variable total has been declared," which implies that the code that you have been asked to write is within some existing code. Is that right? If so then the redeclaration will be due to the single declaration that you added. Have you tried removing your declaration?



There also seems to be missing a method declaration around the code that appears after the using statement.
?
2016-04-30 23:13:55 UTC
If you want to teach your small kid to read popular words that may likely run into and which can be exceptions to basic phonetic rules then the thing you need will be here https://tr.im/PXKX5 , Children Learning Reading program.

 Children Learning Reading is a phonetic centered studying system. Which means that it first teaches your child the letters of the alphabet and the looks they make. It then applies this understanding to simply help your youngster find out phrases on the basis of the sounds the words make. The program is designed to train the fundamental "code" for reading initially. Just after it has been learned are conditions, troubles, and modifications introduced.
Pete
2011-10-29 09:48:25 UTC
I don't see any re-declaration of total.



Is your code inside the main function? Also you should include some prompts for the other information like hours and pay.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...