This is the program so far. I need to alter it so that the program is only able
ID: 3625921 • Letter: T
Question
This is the program so far. I need to alter it so that the program is only able to hold up to 5 courses and 5 grades for each course. The one I have here allows the user to input as many courses and grades as they want (This is not what I want). PLEASE HELPPPP!!
#include <iostream>
#include <iomanip>
using namespace std;
// "**" doubles the array
void calculateAverage(float ** nums ,int ncourse,int ngrades){
for(int i =0 ;i < ncourse ;i++)
{
float total =0.0f;
for(int j=0; j< ngrades-1; j++){
total+= nums[i][j];
}
nums[i][ngrades-1] = total/(ngrades-1);
}
}
int main() {
int ncourse=0,ngrades=0;
cout<<"Please enter the number of courses (5 maximum): "<
cin>>ncourse;
cout<<"Please enter the number of grades per course: "<
cin>>ngrades;
//"**" doubles the array nums
float ** nums = new float*[ncourse];
for (int i = 0; i < ncourse; i++)
nums[i] = new float[ngrades+1];
for(int i =0 ;i < ncourse ;i++)
{
for(int j=0; j
{
cout<<"Please enter grade "<<<" for this course "<<<": ";
cin>>nums[i][j];
cout<
}
}
calculateAverage(nums,ncourse,ngrades+1);
for(int i =0 ;i < ncourse ;i++)
{
cout<< "Course "<< i+1 << endl <<endl;
cout<< "Grades : ";
for(int j=0; j<ngrades;j++){
cout<<nums[i][j]<<" ";
}
cout<<"Average :"<<setprecision(4)<<nums[i][ngrades]<<endl;
}
return 0;
}
Explanation / Answer
please rate - thanks
you have 2 calculateAverage
the CRAMSTER editor did a job on your code
hope this is good
#include<iostream>
#include <iomanip>
using namespace std;
// "**" doubles the array
void calculateAverage(float ** nums ,int ncourse,int ngrades){
for(int i =0 ;i < ncourse ;i++)
{
float total =0.0f;
for(int j=0; j< ngrades; j++){
total+= nums[i][j];
}
cout<<"Course "<<i+1<<" Average :"<<setprecision(4)<<total/ngrades<<endl;
}
}
int main() {
int ncourse=0,ngrades=0;
cout<<"Please enter the number of courses (5 maximum): ";
cin>>ncourse;
while(ncourse>5||ncourse<1)
{cout<<"Invalid entry ";
cout<<"Please enter the number of courses (5 maximum): ";
cin>>ncourse;
}
cout<<"Please enter the number of grades per course(5 max): ";
cin>>ngrades;
while(ngrades>5||ngrades<1)
{cout<<"Invalid entry ";
cout<<"Please enter the number of courses (5 maximum): ";
cin>>ngrades;
}
//"**" doubles the array nums
float ** nums = new float*[ncourse];
for (int i = 0; i < ncourse; i++)
nums[i] = new float[ngrades];
for(int i =0 ;i < ncourse ;i++)
{
for(int j=0; j<ngrades;j++)
{
cout<<"Please enter grade "<<j+1<<" for this course "<<": ";
cin>>nums[i][j];
}
}
calculateAverage(nums,ncourse,ngrades);
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.