Hi all,
First time using these board so my apologies if i don't post correctly! (i have read the posting rules so hopefully should be ok!
The problem i've got is that I need to display the wages entered in the correct order at the end of the loop. For a reason i can't find it will only display the last data entered. If anyone could help me with where i've gone wrong that would be great thanks!
Code:
#include<stdio.h>#include<windows.h>
#include<windowsx.h>
/* Author James King, Wages1 Version 3.1 (Option A) for Caroline Cripps CORC1067*/
int main()
{
/*variables and objects here*/
char dept,exit,name[40];
float totWage [40],wage,hours,overtime,com,wklyWage,avgGross;
int count=0,index=0;
system("cls");
/*Executable instructions here*/
printf("Welcome to the Wages1 program.");
while (exit!='n'&&exit!='N')
{
printf("\n\nEnter Employee Code: ");
scanf("%s",&dept);
switch (dept)
{ /*START of FACTORY code*/
case 'F':
case 'f':
printf("\nEnter name: ");
scanf("%s",&name);
printf("Enter hours worked: ");
scanf("%f",&hours);
printf("Enter rate of pay: œ");
scanf("%f",&wage);
/*Displayed outputs*/
printf("\n-----Factory Dept-----");
printf("\nName: %s",name);
printf("\nEmployee Position: %d",count+1);
if (hours>35)
{
overtime=(wage*1.5)*(hours-35);
printf("\nTotal Overtime: œ%0.2f",overtime);
}
totWage[index]=(35*wage)+overtime;
printf("\nWages earned for employee %d: œ%0.2f",count+1,totWage[index]);
count++;
break;
/*end of Factory dept code*/
case 'S': /*START of SALES code*/
case 's':
printf("\nEnter name: ");
scanf("%s",&name);
printf("Enter hours worked: ");
scanf("%f",&hours);
printf("Enter rate of pay: œ");
scanf("%f",&wage);
printf("Enter Commission Earned: œ");
scanf("%f",&com);
/*Displayed outputs*/
printf("\n-----Sales Dept-----");
printf("\nName: %s",name);
printf("\nEmployee Position: %d",count+1);
totWage[index]=(hours*wage)+com;
printf("\nWages earned for employee %d: œ%0.2f",count+1,totWage[index]);
count++;
break;
/*end of Sales dept code*/
case 'A': /*START of ADMIN code*/
case 'a':
printf("\nEnter name: ");
scanf("%s",&name);
printf("Enter hours worked: ");
scanf("%f",&hours);
printf("Enter rate of pay: œ");
scanf("%f",&wage);
/*Displayed outputs*/
printf("\n-----Administration Dept-----");
printf("\nName: %s",name);
printf("\nEmployee Position: %d",count+1);
totWage[index]=hours*wage;
printf("\nWages earned for employee %d: œ%0.2f",count+1,totWage[index]);
count++;
break;
/*end of Administration dept code*/
default:
printf("\n-----UNKNOWN ENTRY-----");
printf("\nPress 'Y' to continue");
}
/*end of SWITCH loop*/
wklyWage=wklyWage+totWage[index];
avgGross=(float)(wklyWage/count);
printf("\n\n\nAre there more employee's? ");
printf("\nEnter 'y' to continue or 'n' to finish.");
printf("\n\n: ");
scanf("%s",&exit);
}
/*end of WHILE loop*/
printf("\n\nThe average pay is œ%0.2f",avgGross);
printf("\nThe Wage bill for this week is œ%0.2f",wklyWage);
/*THIS LOOP WONT DISPLAY ARRAY IN A LIST ONLY THE LAST DATA ENTERED THEN RANDOM DATA
---It should display the wages entered in order next to the number of the employee who entered it----*/
for (index = 0; index < count; index++)
{
printf("\nEmployee no%d earned %0.2f",count+1, totWage[index]);
}
getchar();
getchar();
return 0;
}
Thanks for looking! Only started using C a month ago, so there may well be a few problems. If there are I'm sorry!