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

Loop not working in assignment

pdring
15
Hi everyone,
I have had a look through the site but can't find anything to help with a little problem i am experiencing with a college assignment. I wonder if anyone would like to help out?

My assignment is : the program should prompt the operator to enter the number of contracts negotiated this week.
After all data has been entered, the program should display the following information for each employee:
Number of contracts negotiated
Total pay
Tax payable
Net pay
It should also display the following overall data:
Total number of contracts negotiated
Total amount of pay
Total tax deducted

I have declared the following structure

struct employeeInfo
{
char name [20];
char job [20];
int basicPay;
int taxAllowance;
int totalContracts;

};
struct employeeInfo employee[noEmployees];

i have declared the number of employees as 5, and for each of the 5 employees i have written:

strcpy (employee[0].name, "John Nixon");
strcpy ( employee[0].job, "Team Leader");
employee[0].basicPay = 320;
employee[0].taxAllowance = 5750;

although for each employee ([0] to [4]),the data is different.

The code i have written works perfectly when it comes to displaying info about the individual employees but the only way i can display info about all the employees e.g. total contracts, is to write a line like this:

overallContracts = employee[0].totalContracts + employee[1].totalContracts + employee[2].totalContracts + employee[3].totalContracts + employee[4].totalContracts;

this works fine but seems clumsy to me and also, using this method it seems impossible to find the correct way of obtaining the total tax payable, as each employee has a different tax allowance that must be divided by 52 (weeks) and subtracted from their total pay! Imagine how long that calculation would be if we were dealing with a lot of employees.
I have tried a few attempts at putting some combinations through a for loop (using a count variable), but they all seem to throw back incorrect figures.
Can anyone point me in the right direction to find a solution ?
thanks for any help,
Phil Dring (Cornwall)
Dec 16 '07 #1
4 1331
scruggsy
147 100+
I have tried a few attempts at putting some combinations through a for loop (using a count variable), but they all seem to throw back incorrect figures.
Can anyone point me in the right direction to find a solution ?
That's the way to do it, with a loop.
Why don't you post your non-working loop code so we can figure out the problem?
Dec 16 '07 #2
pdring
15
That's the way to do it, with a loop.
Why don't you post your non-working loop code so we can figure out the problem?
Hi, thanks for replying. first I have inserted the for loop that does work for each employee:
Expand|Select|Wrap|Line Numbers
  1. for (count = 0;count <noEmployees; count++)
  2.           {
  3.            if (employee[count].totalContracts > 5)
  4.                 totalPay =  employee[count].totalContracts + 100;  /* bonus £100 for over 5 contracts*/
  5.  
  6.           totalPay = employee[count].basicPay + (employee[count].totalContracts * 25); /*bonus £25 for each contract*/
  7.           weeklyTaxAllowance = (employee[count].taxAllowance / 52);   /*allowed to earn this befor tax is deducted*/
  8.           taxpayable = (totalPay - weeklyTaxAllowance)* vatRate; /*- weeklyTaxAllowance;  */
  9.           netPay = totalPay - taxpayable;   /* take home pay*/
  10.  
  11.           printf ("\n%s\n\nContract(s) negotiated\t %d\nTotal Pay\t\t œ%0.2f\nTax Payable\t\t œ%0.2f\nNet Pay\t\t\t œ%0.2f ", employee[count].name, employee[count].totalContracts, totalPay,taxpayable, netPay);
  12.           printf ("\n--------------------------------------------------------------");
}

this is the for loop that does not work:

Expand|Select|Wrap|Line Numbers
  1.  for (count = 0;count <noEmployees; count++)
  2.           {
  3.           overallContracts =  employee[count].totalContracts;     /* to find the total amount of contracts*/
  4.           overallTotalPay = (employee[count].basicPay + (employee[count].totalContracts * 25));  /* to find the total amount of pay inc. £25 bonus for each contract*/
  5.           overallTaxpayable = (employee[count].basicPay + (employee[count].totalContracts * 25)- (employee[count].taxAllowance / 52)* vatRate);/*to find tax payable by all staff*/
  6.           }
thanks for looking, any help will be appreciated
Phil.
Dec 16 '07 #3
oler1s
671 Expert 512MB
Look at the equations in your non-working for loop. You have something = employeedata right? But you aren't just repeatedly setting overalltaxPayable equal to something.

You are repeatedly adding to it. Use the += operator, not the = operator.
Dec 16 '07 #4
pdring
15
Look at the equations in your non-working for loop. You have something = employeedata right? But you aren't just repeatedly setting overalltaxPayable equal to something.

You are repeatedly adding to it. Use the += operator, not the = operator.
Thankyou so much, I have now learned to look over the basics before trying to find complicated answers!!
Dec 16 '07 #5

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

Similar topics

6
by: Sybren Stuvel | last post by:
Hi there, Is it possible to use an assignment in a while-loop? I'd like to do something like "loop while there is still something to be read, and if there is, put it in this variable". I've been...
24
by: Andrew Koenig | last post by:
PEP 315 suggests that a statement such as do: x = foo() while x != 0: bar(x) be equivalent to while True:
25
by: skull | last post by:
Hi everybody, it is my first post in this newsgroup. I am a newbie for python though I have several years development experience in c++. recently, I was stumped when I tried to del item of a list...
3
by: Morgan Wolfe | last post by:
Hello. I'm working on some simple code to generate a list of random integers and store them in a 50 element array. I have two conditions that I'm checking, first, that i < length(array) and...
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
8
by: yuyang08 | last post by:
As we all known, each for-loop can be expressed in while statement. Can we also say that each while statement can be expressed in for-statment? Thanks! -Andy
14
TMS
by: TMS | last post by:
I'm working on the definitive igpay atinlay assignment. I've defined a module that has one function: def igpay(word): Its sole purpose is to process a word into pig latin. It seems to work well. ...
5
by: justbovo | last post by:
Hello, My name is Justin. I am working on a part of a Find Memory module for a program. Here's how it works.. I enter '13' at the main menu which branches out to my Find Memory module. I ask...
12
by: zalery | last post by:
so i'm trying to set up this exponents loop, keep in mind this is my first year in computer science so my knowledge of script is somewhat minimal. basically this assignment (or at least part of it)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.