Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
February 17th, 2013, 09:19 AM
Registered User

Join Date: Feb 2013
Posts: 1
Time spent in forums: 43 m
Reputation Power: 0
Help with a program

Programs

Handle the programs next. Ask the user to enter the number of programs that have been completed during the semester. Write a for loop that will execute "number of programs" number of times. It will calculate the total number of program points and maximum number of program points available. The body of the for loop should:

prompt the user for a single program score. This prompt should include the program number.

prompt the user for the maximum possible score for the single progam

add the single program score to the total program points earned

add the maximum possible program score to the total program points available

If programs have been turned in during the semester, calculate the program average using the formula:

Program average = total program points / maximum program points possible * 100
If no programs have been turned in at this point of the semester, set the program average to 0.0.

Quizzes

Quizzes are next. Ask the user to enter the number of quizzes that have been taken during the semester. If the number of quizzes is greater than 0, write a do...while loop that will calculate the total number of quiz points. The body of the loop should:

prompt the user for a single quiz score. This prompt should include the quiz number.

add the single quiz score to the total quiz points earned

If more than 2 quizzes were taken, ask the user for the sum of the two lowest quiz scores and calculate the maximum possible quiz points using the formula:

Maximum Possible Quiz Points = (number of quizzes - 2) * 10
If 2 or fewer quizzes were taken, set the sum of the two lowest quizzes to 0 and calculate the maximum possible quiz points using the formula:

Maximum Possible Quiz Points = number of quizzes * 10
Use the sum of the two lowest quiz scores and the maximum possible quiz points to calculate the quiz average using the formula:

Quiz Average = (total quiz points - sum of the two lowest quiz scores) / Maximum Possible Quiz Points * 100
If no quizzes have been taken at this point in the semester, set the quiz average to 0.0.

Tests

Finally to the tests. Ask the user to enter the number of tests that have been taken during the semester. If the number of tests that have been taken is greater than 0, then write a while loop that will execute "number of tests" number of times and calculate the total number of test points and maximum number of test points available. The body of the loop should:

prompt the user for a single test score. This prompt should include the test number.

prompt the user for the maximum possible score for the single test

add the single test score to the total test points earned

add the maximum possible score to the total test points available

If tests have been taken during the semester, calculate the test average using the formula:

Test average = total test points / maximum test points possible * 100
If no tests have been taken at this point of the semester, set the test average to 0.0.

Quizzes and Tests

The quiz scores and test scores are combined into an overall test average that is used to calculate the average for the course. If tests or quizzes have been taken during the semester, then calculate the overall test average using the formula:

Overall Test Average = (total test points + total quiz points - sum of the two lowest quiz scores) / (maximum test points possible + Maximum Possible Quiz Points) * 100
If no quizzes and tests have been taken at this point in the semester, set the overall test average to 0.0.

Course Average

The course average is the weighted average of the program and overall test averages. The programs are weighted at 40% and the overall tests are weighted at 60%.

Code:
``` #include <iostream>
#include <iomanip>

using namespace std;
int main()
{

int QuizEarnedsum,QuizWorthsum;
float tests,Tearned,TestMax,TestEarnedsum,TestWorthsum,TestAvg,OverTestAvg,CourseAvg;
ProgramEarnedsum=0;
ProgramWorthsum=0;
QuizEarnedsum=0;
QuizWorthsum=0;
TestEarnedsum=0;
TestWorthsum=0;

cout<<"Enter number of programs completed during the semester: ";
cin>>Programs;

for(int i=0;i<Programs;i++)
{
cout<<"Enter points received for program #"<<i+1<<": ";

cout<<"Enter max points for program #"<<i+1<<": ";
cin>>Programtotal;
ProgramWorthsum+=Programtotal;

}

do{
cout << "Enter the total number of quizzes that have been taken during the semester: "<<endl;
cin>>Quizzes;
}while (Quizzes<0);

for (int i=0;i<Quizzes;i++)
{
cout<<"Enter points received for Quiz #"<<i+1<<": ";
cin>>Qearned;
QuizWorthsum=(Quizzes*10);
QuizEarnedsum+=Qearned;
if (Quizzes<=2){
LowQuizzes=0.0;}

if (Quizzes=0){
QuizAvg2=0.0;}

}
if (Quizzes>2){
cout<<"Enter the sum of lowest quizzes: ";
cin>>LowQuizzes;
QuizWorthsum=(Quizzes-2)*10;
QuizAvg2=(QuizEarnedsum*Quizzes-LowQuizzes)/(QuizWorthsum*100);}

{
cout<<"Enter the number of Tests: ";
cin>>tests;

}while(tests<0);

for(int t=0;t<tests;t++){
cout<<"EnterPoints receieved for Test #"<<t+1<<": ";
cin>>Tearned;

cout<<"Enter max points for Test #"<<t+1<<": ";
cin>>TestMax;

TestEarnedsum+=Tearned;
TestWorthsum+=TestMax;
TestAvg=(Tearned*tests)/(TestMax*tests)*100;
}

if (tests=0)
TestAvg=0;

if (tests>0&&Quizzes>0)
{
OverTestAvg=(TestEarnedsum+QuizEarnedsum-LowQuizzes)/(TestWorthsum+QuizWorthsum)*100;
}
if (tests=0 && Quizzes>1)
{
OverTestAvg==0.0;
}

CourseAvg=OverTestAvg*0.6+ProgramAvg*0.4;

cout<<endl;
cout<<endl;
cout<<endl;
cout<<"PointEarnedPrograms: "<<ProgramEarnedsum<<endl;
cout<<"Maxium Possible: "<<ProgramWorthsum<<endl;
cout<<"ProgramAvg: "<< fixed << setprecision(2)<<ProgramAvg<<endl;
cout<<"Quiz Points Earned: "<<QuizEarnedsum<<endl;
cout<<"Quiz Max worth: "<<QuizWorthsum<<endl;
cout<<"Quiz avg: "<<fixed << setprecision(2) <<QuizAvg2<<endl;
cout<<"Test: "<< setiosflags( ios:: fixed ) << setprecision(2) <<TestEarnedsum<<endl;
cout<<"TEST WORTH: "<<TestWorthsum<<endl;
cout<<"TEST AVG: "<<TestAvg<<endl;
cout<<endl;
cout<<"Test and Quizzes: "<<setiosflags( ios:: fixed ) << setprecision(2) <<OverTestAvg<<endl;
cout<<"Course: "<<CourseAvg<<endl;
return 0;
} ```

Any help would be appreciated, im very new to c++ and this program has be going crazy,after putting countless hours into it already.
My major problems is when an input is 0 it makes the averages all set to 0 and i dont know how to fix that. Thanks in advance for any help

#2
February 17th, 2013, 12:37 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,849
Time spent in forums: 3 Months 1 Day 1 h 45 m 21 sec
Reputation Power: 2199
Very nice that you used code tags in your very first post here. Terrible that you completely neglected to indent your code. The primary purpose of code tags is to preserve your code's indentation and hence its readability, so why defeat their purpose like that. And your game of "hide the braces" makes matters even worse; even K&R style is not so perverted as to also hide close braces at the ends of lines. BTW, K&R absolutely depends on proper and consistent indentation, which makes your elimination of indentation far worse.

Here it is properly formatted. Please note the errors that I indicate in red:
Code:
``` #include <iostream>
#include <iomanip>

using namespace std;
int main()
{

int QuizEarnedsum,QuizWorthsum;
float tests,Tearned,TestMax,TestEarnedsum,TestWorthsum,TestAvg,OverTestAvg,CourseAvg;
ProgramEarnedsum=0;
ProgramWorthsum=0;
QuizEarnedsum=0;
QuizWorthsum=0;
TestEarnedsum=0;
TestWorthsum=0;

cout<<"Enter number of programs completed during the semester: ";
cin>>Programs;

for(int i=0;i<Programs;i++)
{
cout<<"Enter points received for program #"<<i+1<<": ";

cout<<"Enter max points for program #"<<i+1<<": ";
cin>>Programtotal;
ProgramWorthsum+=Programtotal;

}

do
{
cout << "Enter the total number of quizzes that have been taken during the semester: "<<endl;
cin>>Quizzes;
} while (Quizzes<0);

for (int i=0;i<Quizzes;i++)
{
cout<<"Enter points received for Quiz #"<<i+1<<": ";
cin>>Qearned;
QuizWorthsum=(Quizzes*10);
QuizEarnedsum+=Qearned;
if (Quizzes<=2)
{
LowQuizzes=0.0;
}

if (Quizzes=0)
{
QuizAvg2=0.0;
}

}

if (Quizzes>2)
{
cout<<"Enter the sum of lowest quizzes: ";
cin>>LowQuizzes;
QuizWorthsum=(Quizzes-2)*10;
QuizAvg2=(QuizEarnedsum*Quizzes-LowQuizzes)/(QuizWorthsum*100);
}

// where's the do in this do-while?
{
cout<<"Enter the number of Tests: ";
cin>>tests;
} while(tests<0);

for(int t=0;t<tests;t++)
{
cout<<"EnterPoints receieved for Test #"<<t+1<<": ";
cin>>Tearned;

cout<<"Enter max points for Test #"<<t+1<<": ";
cin>>TestMax;

TestEarnedsum+=Tearned;
TestWorthsum+=TestMax;
TestAvg=(Tearned*tests)/(TestMax*tests)*100;
}

// why are you setting test to zero here?
//  = assigns a value to the variable, == tests for equality
if (tests=0)
TestAvg=0;

if (tests>0&&Quizzes>0)
{
OverTestAvg=(TestEarnedsum+QuizEarnedsum-LowQuizzes)/(TestWorthsum+QuizWorthsum)*100;
}

// Again with setting test to zero instead of comparing it to zero!
if (tests=0 && Quizzes>1)
{
// comparing OverTestAvg to zero here
//     is useless.  It'll work, but it does nothing.
OverTestAvg==0.0;
}

CourseAvg=OverTestAvg*0.6+ProgramAvg*0.4;

cout<<endl;
cout<<endl;
cout<<endl;
cout<<"PointEarnedPrograms: "<<ProgramEarnedsum<<endl;
cout<<"Maxium Possible: "<<ProgramWorthsum<<endl;
cout<<"ProgramAvg: "<< fixed << setprecision(2)<<ProgramAvg<<endl;
cout<<"Quiz Points Earned: "<<QuizEarnedsum<<endl;
cout<<"Quiz Max worth: "<<QuizWorthsum<<endl;
cout<<"Quiz avg: "<<fixed << setprecision(2) <<QuizAvg2<<endl;
cout<<"Test: "<< setiosflags( ios:: fixed ) << setprecision(2) <<TestEarnedsum<<endl;
cout<<"TEST WORTH: "<<TestWorthsum<<endl;
cout<<"TEST AVG: "<<TestAvg<<endl;
cout<<endl;
cout<<"Test and Quizzes: "<<setiosflags( ios:: fixed ) << setprecision(2) <<OverTestAvg<<endl;
cout<<"Course: "<<CourseAvg<<endl;
return 0;
} ```

Of course, those are just the errors that I happened to spot. Look for more if-statements where you assigned the value instead of testing for equality.

BTW, you should have gotten some warnings. Never ignore warnings! Warnings are much more important than error messages. Never ignore warnings!

PS
Regarding your ignoring warnings, here is what I got when I compiled your code with MinGW gcc:
Quote:
 C:\otros\dcw>g++ -Wall quizes.cpp quizes.cpp: In function `int main()': quizes.cpp:45: warning: assignment to `int' from `float' quizes.cpp:46: warning: assignment to `int' from `float' quizes.cpp:52: warning: suggest parentheses around assignment used as truth value quizes.cpp:63: warning: assignment to `int' from `float' quizes.cpp:88: warning: suggest parentheses around assignment used as truth value quizes.cpp:97: warning: suggest parentheses around assignment used as truth value quizes.cpp:99: warning: statement with no effect quizes.cpp:110: `fixed' undeclared (first use this function) quizes.cpp:110: (Each undeclared identifier is reported only once quizes.cpp:110: for each function it appears in.) quizes.cpp:8: warning: unused variable `float QuizAvg1' C:\otros\dcw>

In particular, note all the "warning: suggest parentheses around assignment used as truth value". Here are the lines of code indicated:
52: if (Quizzes=0)
88: if (tests=0)
97: if (tests=0 && Quizzes>1)
So then I had missed one, the one on line 52.

Note also:
quizes.cpp:99: warning: statement with no effect
Line 99 is OverTestAvg==0.0;
You must be very diligent in distinguishing between assignment (=) and comparing for equality (==).

You should also double-check those statements where you assigned a float to an int, thus truncating off the number's fractional part. If you really want to do that, you should use a cast to show the compiler that is really what you meant to do. Also, be aware that that does not round off the fraction, but rather just chops it off. (int)42.2 becomes 42, but (int) 42.9999999 also becomes 42 and not 43.

Also take care of fixed in line 110 and thereafter. Perhaps you meant ios::fixed. Anyway, this is an actual error which stopped the compiler from building an executable, so how could you have possibly run this program to get the bad results you reported? Always post the code that gave you the error you describe!

Last edited by dwise1_aol : February 17th, 2013 at 01:00 PM.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Help with a program

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |