Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,181 members, 7,807,579 topics. Date: Wednesday, 24 April 2024 at 03:39 PM

C++ Programmers Please HELP! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / C++ Programmers Please HELP! (1763 Views)

Programmers, Please Recommend A Good Laptop For Me. / Python And C++ Programmers Enter! / C# Programmers Please Step In Here (2) (3) (4)

(1) (Reply) (Go Down)

C++ Programmers Please HELP! by bet9ja(m): 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(m): 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(m): 1:37pm On Mar 31, 2017
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)

Kivy Or Django / I Need The Answer To This C++ Assignment By Saturday Please / Need Help On Bot On Telegram

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.