473,403 Members | 2,323 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,403 software developers and data experts.

assignment from hell !!

pdring
15
Hi everybody,
I have compleated an assignment in C for college and was very pleased with myself until I saw that extra marks could be obtained by modifiying the working program to meet a new criteria.
at present the program excepts an integer as 'amount of contracts sold' for each of 5 employees, the employees are defined in a structure with all the information set out in the assignment brief.
the program then (via 'for loops'), calculates pay etc. acording to amount of contracts sold for each employee and displays it in nice little tables !
the new criteria however is for each employee to enter a tarrif code for each contract sold and display how many contracts were sold under each tarrif code, as well as all the info that the original program displays.
to exit from one employee to the next, the values 9 (for tarrif code) and 0 (for amount of contracts) must be entered.
I have tried to achieve this by setting up a for loop with a nested while and a nested if loop, this works but sends very large and very wrong data to the display, if anyone is interested in this problem, I could post the 'problem' loop for you to see, if thats ok let me know.
Thanks
Phil
Jan 12 '08 #1
4 1358
weaknessforcats
9,208 Expert Mod 8TB
Well, let's see the code.
Jan 12 '08 #2
pdring
15
Well, let's see the code.
Thanks, I have been trying to fix my problem and got a little further, but now the values are not showing at all !!

Expand|Select|Wrap|Line Numbers
  1.  for (count = 0;count <noEmployees; count++)
  2.           do
  3.           {
  4.          printf ("%s\nPlease enter the tarrif code:\t",employee[count].name);
  5.          scanf("%d",&tarrifCode);
  6.          printf ("\nnumber of contracts negotiated for this tarrif:\t");
  7.          scanf("%d", &sales);
  8.          printf ("--------------------------------------------------------------\n");
  9.           }
  10.            while (count<noEmployees && tarrifCode!= 9 && noSales[count] != 0);
  11.  
  12.         for (count = 0;count <noEmployees; count++)
  13.            {
  14.            employee[count].totalContracts += sales;
  15.            if (tarrifCode>0 && tarrifCode<6)
  16.            {
  17.              noSales[tarrifCode - 1] += sales;
  18.             }
  19.             }
Jan 13 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
You may have a data design problem.

You say your employees are in a struct. Where are the contracts???

Wouldn't the contracts also be in a struct??

Expand|Select|Wrap|Line Numbers
  1. struct Contracts
  2. {
  3.       int TheTariff;
  4.       int theContractNumber;
  5.  
  6. };
  7.  
Then your Employee has an array of Contracts:
Expand|Select|Wrap|Line Numbers
  1. struct Employee
  2. {
  3.      Contracts theContracts[5];
  4.      unigned int numSold;
  5.      char Name[20];
  6.      //etc...
  7. };
  8.  
As you sell contracts you fill up the Contracts array. The numSold keeps track of how many contracts are sold. At 5 the array is full and no more contracts can be sold.

Now all you need to is take an employee and loop through the contracts array up to numSold and you have all of your information.
Jan 13 '08 #4
pdring
15
Thankyou very much for your help, I have a working program at last!!!
(why do things seem obvious when you have the answer !)
My course is moving on to C++ next, so I guess I will be scanning the archives of this forum pretty soon.
Thanks again,
Phil Cornwall (England).

You may have a data design problem.

You say your employees are in a struct. Where are the contracts???

Wouldn't the contracts also be in a struct??

Expand|Select|Wrap|Line Numbers
  1. struct Contracts
  2. {
  3.       int TheTariff;
  4.       int theContractNumber;
  5.  
  6. };
  7.  
Then your Employee has an array of Contracts:
Expand|Select|Wrap|Line Numbers
  1. struct Employee
  2. {
  3.      Contracts theContracts[5];
  4.      unigned int numSold;
  5.      char Name[20];
  6.      //etc...
  7. };
  8.  
As you sell contracts you fill up the Contracts array. The numSold keeps track of how many contracts are sold. At 5 the array is full and no more contracts can be sold.

Now all you need to is take an employee and loop through the contracts array up to numSold and you have all of your information.
Jan 13 '08 #5

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

Similar topics

22
by: Jim Hubbard | last post by:
I am reposting a portion of a thread that I am involved in under a new topic because it seems that there are still people that believe the whole "DLL Hell" myth. I hope I can shed some light on...
7
by: Mr. Ed | last post by:
I have a base class which has about 150 derived classes. Most of the derived classes are very similar, and many don't change the base class at all. All the derived classes have a unique factory...
6
by: Greg Merideth | last post by:
While I can't post all of the code I'll post snippets but, it appears that C# is *not* assigning a string, inside of a class, a value that I am passing to it using its public set method and I can't...
3
by: x0td | last post by:
In a dialog box to which is passed to it an object of type "aliasrow" derived from datarow, there is a routine that updates the internal 'aliasrow' (termed mar for member alias row), upon the time...
1
by: GreatB | last post by:
Bill Gates died in a car accident. He found himself in Purgatory being sized up by God . .. "Well, Bill, I'm really confused on this call. I'm not sure whether to send you to Heaven or Hell....
6
by: Suresh Jeevanandam | last post by:
Dear all, I read in "Python in a Nutshell" that when we have multiple assignments made on a single line, it is equivalent to have those many simple assignments and that the right side is evaluated...
34
by: Chris | last post by:
Is there ever a reason to declare this as if(*this == rhs) as opposed to what I normally see if(this == &rhs) ?
12
by: siddhu | last post by:
Dear experts, #include <stdio.h> class Base { }; class Der1:public Base {
16
by: Johannes Bauer | last post by:
Hello group, I'm just starting with Python and am extremely unexperienced with it so far. Having a strong C/C++ background, I wish to do something like if (q = getchar()) { printf("%d\n", q);...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.