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
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;
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
#include <iostream>
#include <fstream>
#include <string>
usingnamespace 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;
}
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;
}
#include <iostream>
usingnamespace 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.