SOMEONE PLEASE HELP

I know i need a nested loop of this sort to run this but im not quite sure how to put it together... i want to be able to input any number of tellers and get there total number of days absent over 3 years
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for i=1 to teller 
for j=1 to num_year 
cin>> sick_days 
tottalsick_days+=sick_days 
endinnerfor 
endouterfor 

cout << "How many tellers worked at Nation’s Bank during each of the last three years?";
cin >> numTellers;
cout << "How many days was teller1 out sick during year 1?";
cin >> tellerAbsence;
cout << "How many days was teller1 out sick during year 2?";
cin >> tellerAbsence;
cout << "How many days was teller 1 out sick during year 3?";
cin >> tellerAbsence;
cout << "How many days was teller 2 out sick during year 1?";
cin >> tellerAbsence;
cout << "How many days was teller 2 out sick during year 2?";
cin >> tellerAbsence;
cout << "How many days was teller 2 out sick during year 3?";
cin >> tellerAbsence; 
Last edited on
ok i think ive cleaned it up a little but am still lost
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int numTeller,teller, numYear, sickDays, tottalSickDays;

cout << "How many tellers worked at Nation’s Bank during each of the last three years?";
cin >> numTellers;


for (teller=1; teller>0; teller++)
{
for (numYear=1; numYear>0; numYear++)
	cout << "How many days was" <<teller<< " out sick during year " <<numYear<< "?";
cin >> sickDays;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?";
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?";
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?";
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?";
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?";
cin >> tellerAbsence; 
   cin>> sickDays 
   tottalSickDays+=sickDays 
   endinnerfor 
   endouterfor 
I'm not sure if this matches your revised code, but I think it does what you're looking for...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	int tellers;
	cout << "How many tellers worked at Nation\'s Bank during each of the last three years? ";
	cin >> tellers;

	int daysAbsent;
	int totalAbsences = 0;

	for(int year = 1; year <= 3; year++)//loops 3 times for each year
	{
		for(int i = 0; i < tellers; i++)//totals absences of all tellers for one year
		{
			cout << "Please enter the number of days absent for teller " 
				<< i + 1 << " in year " << year << ": ";
			cin >> daysAbsent;
			totalAbsences = daysAbsent + totalAbsences;
		}
	}

	cout << "The total number of absences over the last 3 years were: " << totalAbsences <<endl;

	system("pause");
    return 0;
}
Ignore that I'm including fstream and string... You're not going to need those. Those were from the program I had written in the file previously.
ok nowwww ive got everything straitened up and atleast it compiles... but still not right??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
cout << "How many tellers worked at Nation’s Bank during each of the last three years?";
cin >> numTeller;


for (teller=1; teller <= numTeller ; teller++)
{
for (numYear=1; numYear <=3; numYear++)
	cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?" <<endl;
cin >> sickDays;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?"<<endl;
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?"<<endl;
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?"<<endl;
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?"<<endl;
cin >> tellerAbsence;
cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?"<<endl;
cin >> tellerAbsence;
return numYear;
}
return teller;
   
   system("pause");
   return 0;
}
actually i think this is all i need???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>


using namespace std;

int main()
{

int numTeller, tellerAbsence, teller, numYear, sickDays, tottalSickDays;

cout << "How many tellers worked at Nation’s Bank during each of the last three years?";
cin >> numTeller;


for (teller=1; teller < numTeller ; teller++)
{
for (numYear=1; numYear < 3; numYear++)
	cout << "How many days was teller " <<teller<< " out sick during year " <<numYear<< "?" <<endl;
	cin >> sickDays;
	
return numYear;
}
return teller;
   
   system("pause");
   return 0;
}
Yeah that's more or less right. The only thing is that since you're inside your main function you aren't going to return numYear or teller. One function can only return one thing. Also, you need to add some code to actually total up your sick days. Right now, sickDays isn't actually doing anything. It's just getting reassigned memory every iteration of your for loop.
Start by initializing totalSickDays to 0 when you declare it, and add a statement like this inside your nested for loop:

 
totalSickDays = totalSickDays + sickDays;
A Nick you are a life saver....
I'm glad I could help!
Topic archived. No new replies allowed.