I'm a beginner and I need help with a C code to define a structure. I understand some of the basic concepts but I just have trouble conceptualizing and putting the code together.
Write C Code to define a structure for employee. Each employee will have an employee number, first name, last name, hourly rate and number of hours worked.
#include <stdio.h>
struct Employee
{
int employeenumber[50];
string firstname;
string lastname;
float hourlyrate;
int hourswork;
||=== Build: Debug in Question9 (compiler: GNU GCC Compiler) ===|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|5|error: 'string' does not name a type|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|6|error: 'string' does not name a type|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp||In function 'int main()':|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|20|error: 'struct Employee' has no member named 'firstname'|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|23|error: 'struct Employee' has no member named 'lastname'|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|35|error: cannot convert 'int*' to 'const char*' for argument '1' to 'int puts(const char*)'|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|37|error: 'struct Employee' has no member named 'firstame'|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|39|error: 'struct Employee' has no member named 'lastname'|
C:\Users\shanike mc killup\Desktop\Important Documents\Dev-C++ Programs\Question9\main.cpp|43|warning: too many arguments for format [-Wformat-extra-args]|
||=== Build failed: 7 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
Are you using c or c++? In c strings are most often represented as character arrays. In c++ you need to add #include <string> and access it through the std:: namespace (std::string firstname).
Also, you can't use printf or scanf with C++ strings.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
he is using c. Its gcc not g++ and the assignment text says 'in C'.
I believe one of the problems is confusion that %s is needed for the 'strings'; %d and %f will both make a mess.
also, string is not a thing. use char[maxlength]; where maxlength is appropriate to your problem, probably a #define constant at the top of the program.
finally, my C is a bit rusty (thought I tend to write Cish c++ at times) ... in C specifically you MAY need to typdef structs to make them a type, otherwise you just get 1 instance of the thing or whatever you tagged onto the last brace when it is defined (?)