Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

can someone help explain how this code works

OpenStudy (anonymous):

#include<iostream> using namespace std; const int NUMVALUES=10; // this is the constant value void unweighted(double, double, double, double); double weighted(double, double, double, double); int main() { double sum=0; int i, j; double number=0; double s1,s2,s3,s4; double t1=0, t2=0, t3=0, t4=0; for(i=1;i<NUMVALUES;i++) { cout<<"enter the value of the test scores: "<<i<<endl; cin>>s1; t1+=s1; cin>>s2; t2+=s2; cin>>s3; t3+=s3; cin>>s4; t4+=s4; cout<<"student "<<i<<" your weighted average is: "<<weighted(s1, s2, s3, s4)<<endl;//prints out the average score for the test scores } cout<<"the unweighted average of the test scores are"<<unweighted(t1, t2, t3, t4)<<endl;// prints the unweighted average for each student return 0; } double weighted(double t1, double t2, double t3, double t4)//this function takes four doubles that are used used to calculate return the weighted average for an individual student { double weighted=0; double avgT1, avgT2, avgT3, avgT4; avgT1=t1*.10; avgT2=t2*.25; avgT3=t3*.30; avgT4=t4*.35; weighted=(avgT1+avgT2+avgT3+avgT4); return weighted; } void unweighted(double sumT1, double sumT2, double sumT3, double sumT4)//this function takes in the sum of each test then calculates the average of each teset and prints them out { cout<<"the class average is: "<<endl; cout<<"For test 1 is: "<<sumT1/NUMVALUES<<endl; cout<<"For test 2 is: "<<sumT2/NUMVALUES<<endl; cout<<"For test 3 is: "<<sumT3/NUMVALUES<<endl; cout<<"For test 4 is: "<<sumT4/NUMVALUES<<endl; cout<<endl; }

OpenStudy (anonymous):

Which parts do you have problems understanding?

OpenStudy (anonymous):

@Recursing The for loop and the 2 functions

OpenStudy (rsmith6559):

The for loop looks to loop through 10 students asking for scores from four tests that they've taken. The functions do what the comments say they do. This code isn't technically difficult, it's just written poorly. The variable name stink. Commenting would help this code too. Take a copy of this code and do some global edits to make it more readable to you, and what it does will become apparent.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!