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

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 17th, 2013, 08:19 AM
silkshadow00 silkshadow00 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 silkshadow00 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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()
{

float Programs,ProgramEarnedsum,ProgramWorthsum,ProgramAvg,Programgrade,Programtotal,QuizAvg2,QuizAvg1,Qui  zzes,LowQuizzes,Qearned;
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<<": ";
cin>>Programgrade;

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

ProgramAvg=(Programgrade*Programs)/(Programtotal*Programs)*100;
}




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

Reply With Quote
  #2  
Old February 17th, 2013, 11:37 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,125 dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 14th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 16 h 49 m 34 sec
Reputation Power: 1949
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()
{

    float Programs,ProgramEarnedsum,ProgramWorthsum,ProgramAvg,Programgrade,Programtotal,QuizAvg2,QuizAvg1,Qui    zzes,LowQuizzes,Qearned;
    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<<": ";
        cin>>Programgrade;

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

        ProgramAvg=(Programgrade*Programs)/(Programtotal*Programs)*100;
    }

    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 12:00 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC 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 
Rate This Thread:


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap