Hi
I am trying to write a simple C program with devc++ as the complier
using the concept of arrays. I cannot get the program to compile
without mutiple errors. If anyone has the time to help me I would
really apprecaite it.
Thanks SK
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME[20]
# define EMPLOYEES[1000]
/*Define the structure.*/
struct EMP_WeeklyPay
{
char first_name[FULLNAME];
char last_name[FULLNAME];
float RegHr;
float wage;
float OTHr;
float OTHrPay;
float GrossPay;
}
/*Rename the structure syntax.*/
typedef EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
/*Strings in input*/
char department[20], fn[FULLNAME], ln[FULLNAME], char again;
/*temporary float*/
float wage, float OTwage, float hours, float RegHr,
float OTHrPay, float OTHr, float GrossPay;
printf("\n\nMou ntain Pacific Corporation\n") ;
printf("Departm ent Salary Program\n\n");
printf("Please enter the name of the department: ");
scanf("%s", department);
/*Loop to read in employee wage data*/
for (n = 0; n < EMPLOYEES; ++n){
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &Fname, &Lname);
printf("\nPleas e enter the hourly wage for the employee:
");
scanf("%f", &wage);
printf("\nPleas e enter the number of hours worked this"
" week: ");
scanf("%f", &hours);
printf("\nThank you. Process another employee?");
scanf("%s", &again);
}
/*Read in the input*/
numemp = scanf("%11s%11s %f%f%f%f%f", fn, ln, &RegHr,
&wage, &OTHr, &OTHrPay, &GrossPay);
/*Check if user is done*/
printf("\nThank you. Process another employee?");
scanf("%s", &again);
while(again == 'Y' || again == 'y');
if(again != 'Y' && again !='y');
printf("End of processing\n\n\ n");
/*Process the input*/
if(num == 7)
{
if (RegHr > 40)
{
OTHr = hours - 40;
OTHrPay = OT * OTHr * wage;
RegHrPay = 40.0 * wage;
}
else
{
RegHrPay = hours * wage;
OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay;
strncpy(employe e[n].first_name, fn, FULLNAME-1);
employee[n].first_name[FULLNAME-1] = '\0';
strncpy(employe e[n].last_name, ln, FULLNAME-1);
employee[n].last_name[FULLNAME-1] = '\0';
employee[n].regularhours = RegHr;
employee[n].wage = wage;
employee[n].overtimehours = OTHr;
employee[n].overtimepay = OTHrPay;
employee[n].GrossPay. = GrossPay;
++count;
}
/*Print Table*/
printf("\n\nMou ntain Pacific Corporation\n") ;
printf("Departm ent Salary Program\n\n");
printf("Employe e Reg Hrs "
"Overtime Hrs Gross\n");
printf("-----------------------------------------"
"-------------------------\n\n");
for(n=0; n < count; ++n) {
printf("%-35s%-17s%12f%10f%12f %10f%%5f",
employee[n].first_name,
employee[n].last_name, employee[n].RegHr,
employee[n].wage, employee[n].OTHr, employee[n].OTHrPay,
employee[n].GrossPay);
}
} 8 2122
"SK" <ba******@aol.c om> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com Hi I am trying to write a simple C program with devc++ as the complier using the concept of arrays. I cannot get the program to compile without mutiple errors.
The errors are there for a reason. They tell you (approximately) what is
wrong and (approximately) where. Usually a program that spits out numerous
errors actually has rather less. Fixing errors at the start tends to get rid
of many error messages that occur later. I will make a few suggestions to
get you started --- your compiler is probably already making some of the
same suggestions.
If anyone has the time to help me I would really apprecaite it. Thanks SK //Specs to be added later
//C Libraries #include <stdio.h> #include <math.h> #include <string.h>
//Global Constants # define FULLNAME[20] # define EMPLOYEES[1000]
You don't use brackets to #define constants (or equals signs):
# define FULLNAME 20
# define EMPLOYEES 1000
/*Define the structure.*/ struct EMP_WeeklyPay { char first_name[FULLNAME]; char last_name[FULLNAME]; float RegHr; float wage; float OTHr; float OTHrPay; float GrossPay; }
Any struct (or class in C++) must have a semi-colon after the closing
bracket.
/*Rename the structure syntax.*/ typedef EMP_WeeklyPay EWP;
/*Create an array of structures.*/ EWP emp[EMPLOYEES];
/*Counters*/ int n, numemp; int count = 0;
/*Strings in input*/ char department[20], fn[FULLNAME], ln[FULLNAME], char again;
You can't repeat the type char in a single statement. It is either:
char a, b;
or
char a; char b;
Never
char a, char b;
i.e., you need to use a semi-colon before you can use char a second time. /*temporary float*/ float wage, float OTwage, float hours, float RegHr, float OTHrPay, float OTHr, float GrossPay;
Same problem, but this time with float instead of char.
--
John Carson
"SK" <ba******@aol.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com Thank you very much. SK
You're welcome. One other thing. Your code was lacking a main() function and
won't work without one.
The only thing you are allowed to do at global scope (i.e., at the outermost
level of a file) is make declarations and definitions. Any function calls
must be nested inside other functions --- unless this is done as part of a
definition. For this and other reasons, any standard program must define a
main() function within which other function calls occur. To illustrate, a
file:
#include "stdlib.h"
printf("Test\n" );
won't compile.
Instead, you need:
#include "stdlib.h"
int main()
{
printf("Test\n" );
}
--
John Carson
I should have remembered that one. Thanks. It seems to be compiling
better and I am now seeming to be able to correct many more of the
errors.
Thanks again. SK
I managed to essentially corect all of the errors but ones concerned
with how I am placing my data into the memory. I am getting error
descriptions of
(Line 134)C:\Document s and Settings\Owner\ My Documents\HELPC OMP.c
subscripted value is neither array nor pointer
I am trying to add in the information from each employee however I
think I am declaring the memory location erroneously. It is essentially
the later thirdof the program.
Any thoughts??
SK
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME 20
# define EMPLOYEES 1000
//Global Defined Constant
const float OT = 1.5;
//Global Variable Declaratives
FILE*inp;
//Global Constants
# define FULLNAME 20
# define EMPLOYEES 1000
char fn[10];
char ln[10];
char department[20];
char again;
int count_EMP;
int number_EMP;
float wage;
float OTwage;
float hours;
float RegHr;
float RegHrPay;
float OTHrPay;
float OTHr;
float GrossPay;
int Main(void)
{
/*Define the structure.*/
struct EMP_WeeklyPay
{
char first_name[FULLNAME];
char last_name[FULLNAME];
float RegHr;
float wage;
float OTHr;
float OTHrPay;
float GrossPay;
};
/*Rename the structure syntax.*/
typedef struct EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
printf("\n\nMou ntain Pacific Corporation\n") ;
printf("Departm ent Salary Program\n\n");
printf("Please enter the name of the department: ");
scanf("%s", department);
/*Loop to read in employee wage data*/
for (n = 0; n < EMPLOYEES; ++n){
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &fn, &ln);
printf("\nPleas e enter the hourly wage for the employee:
");
scanf("%f", &wage);
printf("\nPleas e enter the number of hours worked this"
" week: ");
scanf("%f", &hours);
printf("\nThank you. Process another employee?");
scanf("%s", &again);
}
/*Read in the input*/
numemp = scanf("%11s%11s %f%f%f%f%f", fn, ln, &RegHr,
&wage, &OTHr, &OTHrPay, &GrossPay);
/*Check if user is done*/
printf("\nThank you. Process another employee?");
scanf("%s", &again);
while(again == 'Y' || again == 'y');
if(again != 'Y' && again !='y');
printf("End of processing\n\n\ n");
/*Process the input*/
if(number_EMP == 7)
{
if (RegHr > 40)
{
OTHr = hours - 40;
OTHrPay = OT * OTHr * wage;
RegHrPay = 40.0 * wage;
}
else
{
RegHrPay = hours * wage;
OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay;
strncpy(count_E MP[n].first_name, fn, FULLNAME-1);
count_EMP[n].first_name[FULLNAME-1] = '\0';
strncpy(count_E MP[n].last_name, ln, FULLNAME-1);
count_EMP[n].last_name[FULLNAME-1] = '\0';
count_EMP[n].regularhours = RegHr;
count_EMP[n].wage = wage;
count_EMP[n].overtimehours = OTHr;
count_EMP[n].overtimepay = OTHrPay;
count_EMP[n].GrossPay = GrossPay;
++count;
}
/*Print Table*/
printf("\n\nMou ntain Pacific Corporation\n") ;
printf("Departm ent Salary Program\n\n");
printf("Employe e Reg Hrs "
"Overtime Hrs Gross\n");
printf("-----------------------------------------"
"-------------------------\n\n");
for(n=0; n < count; ++n) {
printf("%-35s%-17s%12f%10f%12f %10f%%5f",
count_EMP[n].first_name,
count_EMP[n].last_name, employee[n].RegHr,
count_EMP[n].wage, count_EMP[n].OTHr,
count_EMP[n].OTHrPay,
count_EMP[n].GrossPay);
}
}
"SK" <ba******@aol.c om> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com I managed to essentially corect all of the errors but ones concerned with how I am placing my data into the memory. I am getting error descriptions of
(Line 134)C:\Document s and Settings\Owner\ My Documents\HELPC OMP.c subscripted value is neither array nor pointer
It means exactly what it says. count_EMP is an integer, not an array and not
a pointer. Further, it is unrelated to your struct so using the dot operator
in conjunction with count_EMP[n] makes no sense.
--
John Carson
SK wrote: I managed to essentially corect all of the errors but ones concerned with how I am placing my data into the memory. I am getting error descriptions of
(Line 134)C:\Document s and Settings\Owner\ My Documents\HELPC OMP.c subscripted value is neither array nor pointer
I am trying to add in the information from each employee however I think I am declaring the memory location erroneously. It is essentially the later thirdof the program.
Any thoughts?? SK
Some other errors below.
//C Libraries #include <stdio.h> #include <math.h> #include <string.h>
//Global Constants # define FULLNAME 20 # define EMPLOYEES 1000
//Global Defined Constant const float OT = 1.5;
//Global Variable Declaratives FILE*inp;
//Global Constants # define FULLNAME 20 # define EMPLOYEES 1000
char fn[10]; char ln[10]; char department[20]; char again;
int count_EMP; int number_EMP;
float wage; float OTwage; float hours; float RegHr; float RegHrPay; float OTHrPay; float OTHr; float GrossPay;
int Main(void)
int main()
main must be lower case.
{ /*Define the structure.*/ struct EMP_WeeklyPay { char first_name[FULLNAME]; char last_name[FULLNAME]; float RegHr; float wage; float OTHr; float OTHrPay; float GrossPay; };
This isn't wrong, but it makes more sense to declare this outside the
main function not inside it. That way it is available to the whole
program, not just the main function. At the moment it doesn't matter
because the main function is your whole program, but later on...
/*Rename the structure syntax.*/ typedef struct EMP_WeeklyPay EWP;
Diito, and this is C style programming. Are you trying to learn C or
C++? If you are trying to learn C you really should be posting to
comp.lang.c otherwise people are going to suggest all sorts of C++
solutions to your problems.
If you are trying to learn C++ then you can drop the struct
typedef EMP_WeeklyPay EWP;
But really you should also ask yourself, why do I need the same struct
named two different ways? I cannot think of a good reason so you should
just choose EMP_WeeklyPay or EWP and stick with it.
/*Create an array of structures.*/ EWP emp[EMPLOYEES];
/*Counters*/ int n, numemp; int count = 0; printf("\n\nMou ntain Pacific Corporation\n") ; printf("Departm ent Salary Program\n\n"); printf("Please enter the name of the department: "); scanf("%s", department);
/*Loop to read in employee wage data*/ for (n = 0; n < EMPLOYEES; ++n){
printf("\nEnter employee # %d: ", count_EMP); scanf("%s %s", &fn, &ln);
printf("\nPleas e enter the hourly wage for the employee: "); scanf("%f", &wage);
printf("\nPleas e enter the number of hours worked this" " week: "); scanf("%f", &hours);
printf("\nThank you. Process another employee?"); scanf("%s", &again);
}
/*Read in the input*/ numemp = scanf("%11s%11s %f%f%f%f%f", fn, ln, &RegHr, &wage, &OTHr, &OTHrPay, &GrossPay);
/*Check if user is done*/ printf("\nThank you. Process another employee?"); scanf("%s", &again);
while(again == 'Y' || again == 'y');
This loop is wrong. I think you meant
do
{
printf("\nThank you. Process another employee?");
scanf("%s", &again);
}
while(again == 'Y' || again == 'y');
When you write a loop, you have to put the code that you ant to loop
over inside the brace. The compiler can't guess what you want to loop over. if(again != 'Y' && again !='y'); printf("End of processing\n\n\ n");
Well this will print a message, but then it will carry on the loop. If
you want to exit the for loop here then you have to say so. Also the
semi colon is incorrect.
if(again != 'Y' && again !='y')
{
printf("End of processing\n\n\ n");
break; // this will quit the for loop
}
/*Process the input*/ if(number_EMP == 7) {
if (RegHr > 40) { OTHr = hours - 40; OTHrPay = OT * OTHr * wage; RegHrPay = 40.0 * wage; }
else { RegHrPay = hours * wage; OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay; strncpy(count_E MP[n].first_name, fn, FULLNAME-1); count_EMP[n].first_name[FULLNAME-1] = '\0';
strncpy(count_E MP[n].last_name, ln, FULLNAME-1); count_EMP[n].last_name[FULLNAME-1] = '\0';
count_EMP[n].regularhours = RegHr; count_EMP[n].wage = wage; count_EMP[n].overtimehours = OTHr; count_EMP[n].overtimepay = OTHrPay; count_EMP[n].GrossPay = GrossPay;
++count; } /*Print Table*/
printf("\n\nMou ntain Pacific Corporation\n") ; printf("Departm ent Salary Program\n\n");
printf("Employe e Reg Hrs " "Overtime Hrs Gross\n");
printf("-----------------------------------------" "-------------------------\n\n");
for(n=0; n < count; ++n) { printf("%-35s%-17s%12f%10f%12f %10f%%5f", count_EMP[n].first_name, count_EMP[n].last_name, employee[n].RegHr, count_EMP[n].wage, count_EMP[n].OTHr, count_EMP[n].OTHrPay, count_EMP[n].GrossPay); }
}
Really this looks to me like you are trying to learn C. You really
should stop posting to comp.lang.c++ and post to comp.lang.c instead of
you are going to get horribly confused.
john /*Check if user is done*/ printf("\nThank you. Process another employee?"); scanf("%s", &again);
while(again == 'Y' || again == 'y');
This loop is wrong. I think you meant
do { printf("\nThank you. Process another employee?"); scanf("%s", &again); } while(again == 'Y' || again == 'y');
When you write a loop, you have to put the code that you ant to loop over inside the brace. The compiler can't guess what you want to loop over.
My suggstion above is rubbish. I'm not sure what you meant. Perhaps this
do
{
printf("\nThank you. Process another employee?");
scanf("%c", &again);
}
while(again != 'y' && again != 'Y' && again != 'N' && again
!= 'n');
i.e. loop until the user answers Y or N.
But anyway note there is another error, you shuld have %c for a char, %s
is for strings.
scanf("%c", &again);
You're eventually going to get this to compile and then you are going to
find out that you have all sorts of even harder logic errors to fix.
Getting your code to compile is only the first step. I would say that
you should have started with a smaller program and only built up to this
bigger program gradually. You could be biting off more than you can
chew, if you are then you will only get frustrated, instead of learning
anything. But anyway good luck!
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: da Vinci |
last post by:
OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.
How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?
Basically: "Press any key to continue..."
I beleive that I am looking for is something along the lines of a....
|
by: atlanta |
last post by:
this is a simple C++ program to write.
"Write a complete and functioning structured program that successfully
compiles on Visual C++ 6,
that uses two-dimensional array (5x5) that stores numbers. Read in the
numbers, print them forward and backward."
i dont know How to write C++.
|
by: Vitali Gontsharuk |
last post by:
Hi!
I have a problem programming a simple client-server game, which is
called pingpong ;-)
The final program will first be started as a server (nr. 2) and then as
a client. The client then sends the message "Ping" to the server, which
reads it and answers with a "Pong".
The game is really simple and the coding should be also very simple! But
for me it isn't.
By the way, the program uses datagram sockets (UDP). And, I'm using
|
by: Wally |
last post by:
Is there a simple code for reading and transmitting infa red for the
tv, vcr, dvd etc.
I have a client who has limited/no use of her hands. I've purchased a
tira-2 infa red receiver/transmitter so she could control her tv,
vcr,dvd via the computer using dragon speak. the program they
suggested to use was Girder.. But this is a very complicated program
for her to use.
All I need is a simple little program that with record a infa red
|
by: pamelafluente |
last post by:
I am beginning aspNet, I know well win apps.
Need a simple and schematic code example to start work.
This is what I need to accomplish:
----------------------
Given button and a TextBox on a web form when one presses the button on
the web form on a client pc, the sql query which is contained in the
text box is sent to a vb net application on a server pc. The win
application sends the query to the database, collects the results,
| |
by: pamelafluente |
last post by:
I am still working with no success on that client/server
problem. I need your help. I will submit simplified versions
of my problem so we can see clearly what is going on.
My model:
A client uses IE to talk with a server.
The user on the client (IE) sees an ASP net page containing
a TextBox. He can write some text in this text box and
push a submit button.
|
by: toch3 |
last post by:
i am writing a c program that is basically an address book. the only
header we are using is #include<stdio.hwe are to use a global array,
loops, and pointers. we are to have a menu at the beginning. 1. add new
record 2. search for a record 3 modify a record 4. delete a record 5.
view all records 6.exit in each of these menu's we are to be able to
print the record to an exterior printer.
: i have started my global array, and program, but...
|
by: dav3 |
last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and have yet to find a solution.
My program is supposed to read in a txt file which contains 2 lines of numbers. Program reads the file and stores each line as a string, then converts each character to an integer. Once char is converted to an int the...
|
by: astrogirl77 |
last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's.
I code in an old version of Visual Basic 4.0, I have a simple app that is about 3 and a half pages of code long it does some relatively simple math additions and subtractions
The problem I have is that some numbers get to be very large integers and VB automatically converts this to scientifc notation, what I need is...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |