473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Fuction to read in and sum data to a record:

void get_workdata(ifstream& in, emp_rec anc_emp[], int n)
{
int x;
double y;
int cnt = 0;
for (int i=0; i<n; i++)
{
anc_emp[i].hoursworked = 0.0;
anc_emp[i].commission = 0.0;
}
in >> x;
while (x >= 0)
{
in >> y;
for (int i=0; i<n; i++)
{
if (x = anc_emp[i].idnum)
{
anc_emp[i].hoursworked = anc_emp[i].hoursworked + y;
cnt = cnt;
}
if (x != anc_emp[i].idnum)
{cnt++;
}
}
if (cnt = n)
{
cout << "Error: unassignmed ID# " << x << " with " << y << " hours."
<< endl;
}
in >> x;
}

}








So basically the first data set is this:
(employee name, idnumber, payrate)
tom 46 7.50
saLLy 53 8.25
VanEssA 91 5.85

The second data set is this:
(idnumber, hours worked)
91 10.0
11 15.0
46 8.0
91 4.5
53 20.0
91 6.75
56 40.0
-3

I am supposed to create employee records and sum the hours worked and figure the total pay. So far, I have everything down EXCEPT for my function that reads in the idnumber, then the hours worked for that idnumber. If the id matches an id from file1, the hours need to be added. If the id number doesn't match, an error message will print that states it's an invailid id number. I denoted 'x' as the idnumber being read in and 'y' as the hours worked for that id number.

Here is my algorithm:

1. Read in the first id number
2. While id number is not negative,
3. Read in hours worked.
4. Set up a For loop
a) If x equals an idnumber from file 1, then add the hours worked to that
record.
b) Else: add one to 'cnt'

After for loop runs through all the id numbers from file 1,
5. If cnt = n (the number of employee records) then the current x value doesn't match any of the id numbers from file1 and is an invalid id number and a message will print.

6. Read in x (next id number)

My program compiles, but when I run it, I get this:

Error: unassigned ID# 91 with 10 hours.
Error: unassigned ID# 91 with 15 hours.
Error: unassigned ID# 91 with 8 hours.
Error: unassigned ID# 91 with 4.5 hours.
Error: unassigned ID# 91 with 20 hours.
Error: unassigned ID# 91 with 6.75 hours.
Error: unassigned ID# 91 with 40 hours.

Could anyone please look at my function get_workdata and see if you can find any errors because I am stuck!
Jul 11 '08 #1
3 1595
Laharl
849 Expert 512MB
You need a second = in the if condition Anywhere = is legal syntax, == is as well, which can lead to some interesting errors...

Also, please try to use CODE tags when you post code.
Jul 12 '08 #2
With the '==' after my if statement, this is what I'm getting:

Error: unassignmed ID# 91 with 10 hours.
Error: unassignmed ID# 11 with 15 hours.
Error: unassignmed ID# 46 with 8 hours.
Error: unassignmed ID# 91 with 4.5 hours.
Error: unassignmed ID# 53 with 20 hours.
Error: unassignmed ID# 91 with 6.75 hours.
Error: unassignmed ID# 56 with 40 hours.

I only want 11, 56, and 67 to display error messages. I can't figure out why all the id numbers are displaying error messages. Any other ideas?
Jul 12 '08 #3
Nevermind I worked it out.
Jul 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: pisscot | last post by:
Lind Apr 13, 6:32 am show options Newsgroups: comp.lang.c From: piss...@gmail.com (Lind) - Find messages by this author Date: 13 Apr 2005 06:32:15 -0700 Local: Wed,Apr 13 2005 6:32 am...
29
by: pb648174 | last post by:
I have a very long transaction that runs on the same database that other users need to use for existing data. I don't care if they see data from the transaction before it is done and am only using...
1
by: Szaki | last post by:
I use a BulkLoad to import file.xml to my base MS Server 2000. To import this xml file I need schema file. Mayby you know how to do this file mechanicy f.g. mayby somebody have some script in .net...
3
by: Vic | last post by:
Dear All, I have a database of laboratory records in Access 2000. There is one form which acts as an interface to input experimetal data. This form incorporates information from several tables....
5
by: seddy | last post by:
Hello ! I`m kinda new to it so I found this `job` very hard therefor I ask for Your help. So, the thing is... I have this XML file ( http://www.izishop.net/export.php ) which I need to open...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
7
by: Problematic coder | last post by:
Dim objdr As Data.OracleClient.OracleDataReader = Nothing Dim objcnn As Data.OracleClient.OracleConnection = Nothing Dim objcom As Data.OracleClient.OracleCommand objcom = New...
3
by: maylee21 | last post by:
hi, anyone can help me figure out how to read data from a text file like this: 10980012907200228082002 and extract the data according to this kind of format: Record type 1 TY-RECORD ...
3
by: Osamede.Zhang | last post by:
I have some code like this: SqlCommand cmd = new SqlCommand("get_storeid_byuser", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.