₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,307 members, 8,421,256 topics. Date: Saturday, 06 June 2026 at 06:32 AM

Toggle theme

C++ Programmers Please HELP! - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingC++ Programmers Please HELP! (1929 Views)

1 Reply (Go Down)

C++ Programmers Please HELP! by bet9ja(op): 8:33am On Mar 31, 2017
the question is
Write a program that computes the average number of hours a student spends on programing and on Biology over a long week end. Your program should ask the user how many students there are as well as the number of days in the long week. For each student the user has to enter the number of hours spent programing and the number of hours spent studying Biology.

The program should output the average number of hours spent programming as well as studying Biology for each student. The program should also output which subject the student spent the most time on.

The program i have so far is this....


#include <iostream>
using namespace std;

int main()
{
//This program finds the average number of hours a day
// That a student spent studying biology and programming

int numStudents, numDay;
float numHours, total, average;
int student, day = 0; // these are the counter for the loops

cout << "This program will find the average number of hours a day"
<< " That a student spent studying biology and programming\n\n";
cout << "How many students are there?" << endl << endl;
cin >> numStudents;
cout << "Enter the number of days in the long weekend" << endl << endl;
cin >> numDay;

for ( student = 1; student <= numStudents; student++)
{
total = 0;
for(day = 1; day <= 2; day++)
{
cout << "Please enter the number of hours worked by student "
<< student << " on day " << day << "." << endl;
cin >> numHours;

total = total + numHours;
}
average = total / 2;

cout << endl;
cout << "The average number of hours per day spent programming "
<< "by student " << student << " is " << average
<< endl << endl << endl;

cout << "The average number of hours per day spent studying biology "
<< "by student " << student << " is " << average
<< endl << endl << endl;

}
return 0;

}
Re: C++ Programmers Please HELP! by LionDeLeo: 9:10am On Mar 31, 2017
Will check and get back to you. Very busy at the moment.
Re: C++ Programmers Please HELP! by bet9ja(op): 9:59am On Mar 31, 2017
LionDeLeo:
Will check and get back to you. Very busy at the moment.
Thank you
Re: C++ Programmers Please HELP! by bet9ja(op):
Big thanks.... Now i got it working .... here is the complete code.....

// This program finds the average time spent programming by a student
// each day over a three day period.

// Olu Ayeni

#include <iostream>
using namespace std;

int main()
{
int numStudents;
int numDays, student, n; // counters for the loops

float progHours, bioHours; // Variable to holds hours spent reading biology and programming
float progTotal, bioTotal; // Variable to holds total hours spent on biology and programming
float progAvg, bioAvg; // Variable to holds average hours spent on biology and programming

cout << "This program will find the average number of hours a day" << endl
<< "each given student spent reading biology and programming over a long weekend\n\n";

cout << "How many students are there ?" << endl << endl;
cin >> numStudents;

cout << "Enter the number of days in the long weekend" << endl;
cin >> numDays;
cout << endl;

for( student = 1; student <= numStudents; student++)
{
progTotal = 0;
bioTotal = 0;
for(n = 1; n <= numDays; n++)
{
cout << "Enter student " << student << " day " << n
<< " programming hrs: " << endl;
cin >> progHours;

cout << "Enter student " << student << " day " << n
<< " biology hrs: " << endl;
cin >> bioHours;

progTotal = progTotal + progHours;
bioTotal = bioTotal + bioHours;
}

progAvg = progTotal / numDays;
bioAvg = bioTotal / numDays;

cout << endl;
cout << "The average number of hours per day spent programming by "
<< "student " << student << " is " << progAvg << endl;
cout << "The average number of hours per day spent on biology by "
<< "student " << student << " is " << bioAvg << endl;

if (progAvg > bioAvg)
cout << "This student averaged more time on programming.";
else if (progAvg < bioAvg)
cout << "This student averaged more time on biology.";
else
cout << "This student spent the same amount of time on both subjects.";
cout << endl << endl << endl;
}

return 0;
}
Re: C++ Programmers Please HELP! by stack1(m): 10:37am On Apr 02, 2017
Good for you, next time also state the errors you might be getting, its easier to get help that way
1 Reply

Programmers, Please Recommend A Good Laptop For Me.Python And C++ Programmers Enter!C# Programmers Please Step In Here234

Please Review The SPA I'm Building With AngularRuby Vs PythonComputer Science Project Topic With Full Write Ups And Software