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
4 1358
Well, let's see the code.
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 !! - for (count = 0;count <noEmployees; count++)
-
do
-
{
-
printf ("%s\nPlease enter the tarrif code:\t",employee[count].name);
-
scanf("%d",&tarrifCode);
-
printf ("\nnumber of contracts negotiated for this tarrif:\t");
-
scanf("%d", &sales);
-
printf ("--------------------------------------------------------------\n");
-
}
-
while (count<noEmployees && tarrifCode!= 9 && noSales[count] != 0);
-
-
for (count = 0;count <noEmployees; count++)
-
{
-
employee[count].totalContracts += sales;
-
if (tarrifCode>0 && tarrifCode<6)
-
{
-
noSales[tarrifCode - 1] += sales;
-
}
-
}
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?? -
struct Contracts
-
{
-
int TheTariff;
-
int theContractNumber;
-
-
};
-
Then your Employee has an array of Contracts: -
struct Employee
-
{
-
Contracts theContracts[5];
-
unigned int numSold;
-
char Name[20];
-
//etc...
-
};
-
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.
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?? -
struct Contracts
-
{
-
int TheTariff;
-
int theContractNumber;
-
-
};
-
Then your Employee has an array of Contracts: -
struct Employee
-
{
-
Contracts theContracts[5];
-
unigned int numSold;
-
char Name[20];
-
//etc...
-
};
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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)
?
|
by: siddhu |
last post by:
Dear experts,
#include <stdio.h>
class Base
{
};
class Der1:public Base
{
|
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);...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |