miscellaneous

Forum > Miscellaneous > Anyone familiar with C++?
Reply To Thread (login)
Brown Stuff [79]
2011-10-01 19:08:26
[13 years, 57 days ago]

I'm suppose to make it ask for employee name, then ask for sick days, then for it to give the total sick days, then give the average sick days.

This is what I have so far, any help will really be appreciated. I know it's not very difficult but it is for me.

include iostream

using namespace std; int main() { int employ1, employ2, employ3, employ4, average; int days1, days2, days3, days4,
total;

cout << "Enter the name of employee #1: ";
cin >> employ1;
cout << "Enter sick days for employee #1: ";
cin >> days1;
cout << "Enter the name of employee #2: ";
cin >> employ2;
cout << "Enter sick days for employee #2: ";
cin >> days2;
cout << "Enter the name of employee #3: ";
cin >> employ3;
cout << "Enter sick days for employee #3: ";
cin >> days3;
cout << "Enter the name of employee #4: ";
cin >> employ4;
cout << "Enter sick days for employee #4: ";
cin >> days4;

total = days1 + days2 + days3 + days4;
average = total / 4;

cout << "Employee:       " << days1 << endl;
cout << "Employee:       " << days2 << endl;
cout << "Employee:       " << days3 << endl;
cout << "Employee:       " << days4 << endl;
cout << "Total sick days: " << total << endl;

return 0;

}


 
Mainor II [155]
2011-10-01 19:13:23
[13 years, 57 days ago]

google c++ guide?


 
Brown Stuff [79]
2011-10-01 19:31:04
[13 years, 57 days ago]

I have done that extensively, have a $150 book and I'm currently taking a beginners course in C++. I'm looking for someone who can help me with this, if you can't that's alright. I'm currently getting error LNK1168, and I'm sure I'm doing something else wrong too.


 
Brown Stuff [79]
2011-10-01 20:35:58
[13 years, 57 days ago]

This is what I have now after changing some stuff. Now it seems my only problem is that the corresponding cout statements are being displayed as a single line when they should be separated.

It's displayed like this:

"Enter the name of employee #1: Enter sick days for employee #1:"

It should be displayed one at a time in their own line

"Enter the name of employee #1: Bob"

"Enter sick days for employee #1: 4"

include (iostream)

using namespace std;

int main()

{ int days1, days2, days3, days4, total;
double average;

cout << "Enter the name of employee #1: "; 
cout << "Enter sick days for employee #1: ";
cin >> days1;
cout << "Enter the name of employee #2: ";
cout << "Enter sick days for employee #2: ";
cin >> days2;
cout << "Enter the name of employee #3: ";
cout << "Enter sick days for employee #3: ";
cin >> days3;
cout << "Enter the name of employee #4: ";
cout << "Enter sick days for employee #4: ";
cin >> days4;

total = days1 + days2 + days3 + days4;
average = total / 4.0;

cout << "The total number of sick days is: " << total << endl;
cout << "The average number of sick days is: " << average << endl;

return 0;

}

If anyone knows how to fix that, I'll be done :)


 
Ender [1]
Administrator
2011-10-01 20:46:22
[13 years, 57 days ago]

Surround your code in pre tags.


 
Big Blitz [8]
2011-10-01 20:48:13
[13 years, 57 days ago]

I have no idea what this is all about, but I need my forum post trophy.


 
Brown Stuff [79]
2011-10-01 22:30:28
[13 years, 57 days ago]

thanks to everyone who helped, finished it :D


 
Dreadbolt [85]
2011-10-04 08:18:07
[13 years, 55 days ago]

im not much of a c++ programmer, but ill be doing it next year in my course. anyways, from what i saw of your code, if c++ supports it like other languages ive tried, would this be more efficient?

making an array that holds objects representing employees, then using a loop to process the array. that way if you wanted to add more employees, it wouldn't take much effort or code repetition.

(btw i'm studying java atm, so c++ might not actually work like this lol)


 
Brown Stuff [79]
2011-10-08 03:52:44
[13 years, 51 days ago]

I'm completely new to C++ so I'm not sure, but I think that is possible with c++. But I'm not advanced enough to know how to do that, 1 more semester after this one and maybe I will be :) good luck with your class when you take it


 
Forum > Miscellaneous > Anyone familiar with C++?
Reply To Thread (login)