Results 1 to 9 of 9

Thread: C++ School Final Project

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    C++ School Final Project

    My teacher asked me to post on this forum for help on my program. I am currently Using Microsoft Visual C++ 6.0 I keep on getting three errors on the first line of my first function. The code is:

    /* Daniel Gonzalez
    Start Date: 01/03/06
    Due Date: 1/11/06
    This program calculates a person's average in a class
    It works by asking the person to input the name of x number categories and how much each is worth**.
    It then asks the person to input how many grades are to be inputed under each category** */

    //--------------------------------------------------------------------------------------
    #include <iostream.h >
    #include <math.h>
    #include <apstring.cpp>
    double average01;
    double average02;
    double average03;
    double average04;
    double average05;
    double average06;
    double average07;
    double average08;
    double average09;
    //--------------------------------------------------------------------------------------
    void cat01(int 1,2,3,4,5,6,7,8,9,addition,average,y,numgrade
    /* Gets the average of up to 9 numbers worth x% of the grade */
    {
    cout << "Enter the amount of grades ";
    cin >> numgrade;
    y=0;
    while (numgrade >0 )
    {
    cin >> 1;
    y++;
    numgrade--;
    cin >> 2;
    y++;
    numgrade--;
    cin >> 3;
    y++;
    numgrade--;
    cin >> 4;
    y++;
    numgrade--;
    cin >> 5;
    y++;
    numgrade--;
    cin >> 6;
    y++;
    numgrade--;
    cin >> 7;
    y++;
    numgrade--;
    cin >> 8;
    y++;
    numgrade--;
    cin >> 9;
    y++;
    numgrade--;
    }
    addition= 1+2+3+4+5+6+7+8+9;
    average01= addition/y;

    }
    //--------------------------------------------------------------------------------------

    -------------------------------------------------------------------------
    Note: I omitted Functions 2-9 because it is the exact same code with the number on the catnumber and the average number being different
    --------------------------------------------------------------------------

    /* The above are a series of functions that are to be called in main. THey are all the same.
    They work by inting 9 variables it then asks the user for how many grades there are
    It then takes the grades and each time it subracts one from the amount until it reaches 0
    thus terminating the loop. At the same time, it adds one to the variable y which is then used
    to keep track of how many it should divide by to get the average. Note that in the Addition part
    of all the grades all the numbers are included because if the loop terminates early, it does not
    take into account the other variables */
    //--------------------------------------------------------------------------------------
    void main()

    {
    apstring cat1;
    apstring cat2;
    apstring cat3;
    apstring cat4;
    apstring cat5;
    apstring cat6;
    apstring cat7;
    apstring cat8;
    apstring cat9;
    double numcat;
    double numper;
    double funcnum;
    double percent1;
    double percent2;
    double percent3;
    double percent4;
    double percent5;
    double percent6;
    double percent7;
    double percent8;
    double percent9;
    char yn;
    /* the above is the declaration of all the variables to be used in main.
    Below is a do-while statment in order to allow the looping of the program.
    Also, the getting of the categories,percents, and the calling of the functions
    follows what was explained above in the functions where it subracts from the number of categories entered
    thus making it so the while loop will have an end when it is properly named */

    do {
    cout << "Enter the amount of categories :";
    cin >> numcat;
    cout << "Enter the names of the categories : "<< endl;
    while ( numcat >0 )
    {

    cin >> cat1;
    numcat--;
    cin >> cat2;
    numcat--;
    cin >> cat3;
    numcat--;
    cin >> cat4;
    numcat--;
    cin >> cat5;
    numcat--;
    cin >> cat6;
    numcat--;
    cin >> cat7;
    numcat--;
    cin >> cat8;
    numcat--;
    cin >> cat9;
    numcat--;
    }
    cout << "Please re-enter the amount of categories ";
    cin >> numper;
    cout << "Enter how much of the percent is each category worth (in decimal form) : ";

    while (numper > 0)
    {
    cin >> percent1;
    numper--;
    cin >> percent2;
    numper--;
    cin >> percent3;
    numper--;
    cin >> percent4;
    numper--;
    cin >> percent5;
    numper--;
    cin >> percent6;
    numper--;
    cin >> percent7;
    numper--;
    cin >> percent8;
    numper--;
    cin >> percent9;
    numper--;
    }
    cout << "Please re-enter the amount of categories: ";
    cin >> funcnum;
    while (funcnum > 0) {
    cat01();
    funcnum--;
    cat02();
    funcnum--;
    cat03();
    funcnum--;
    cat04();
    funcnum--;
    cat05();
    funcnum--;
    cat06();
    funcnum--;
    cat07();
    funcnum--;
    cat08();
    funcnum--;
    cat09();
    funcnum--;
    }


    cout << "If you would like to continue type Y. If you would like to stop press N . "<;
    cin >> yn;

    } while (yn == 'Y' || yn == 'y');
    if (yn == 'N' || yn == 'n')
    cout << "Thank you for using Daniel Gonzalez's Grade Calculator!" << endl;
    cout << "Have a nice day!" << endl;
    }

    /* Ask Mr. Morrel about calling just the average part from the function. Also check for problems.
    At the end of the program give Letter grades like if 80<x> 89 cout B or something like that*/
    -----------------------------------------------------------------------
    The Errors are:
    G://G:\Cpp files\d-gonfinal.cpp(22) : error C2143: syntax error : missing ')' before 'constant'
    G:\Cpp files\d-gonfinal.cpp(22) : error C2143: syntax error : missing ';' before 'constant'
    G:\Cpp files\d-gonfinal.cpp(22) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    d-gonfinal.obj - 3 error(s), 0 warning(s)
    ------------------------------------------------------------------------
    Any help you could give me would be much appreciated.
    Thanks,
    Woomba

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: C++ School Final Project

    1. Post code inside [code][/code] to preserve formating on the forum.
    void cat01(int 1,2,3,4,5,6,7,8,9,addition,average,y,numgrade
    2. Variable names can not start with a number, 1 always means the number 1, not a variable.
    3. If a function has more then one parameter you need to redeclare the type for each one:
    Code:
    void cat(int v1, int v2, int v3, int v4) { ... }
    4. main should have return type int, not void. Add return 0 at the end.
    5. Why does the cat01 function have 9 parameters, and why have you duplicated the function? Do you know how to use arrays? They will make your code a lot easier. Also, you shouldn't declare all variables you need as arguments (between the parentheses), use local variables instead:
    Code:
    void cat01() {
        int numgrade;
        double avarage;
        // etc.
    }
    6. Instead of returning stuff in global variables you should make the functions return the value:
    Code:
    double cat(something) {
        ...
        return sum / number;
    }
    ...
    int main() {
       ...
       double avarage1 = cat(...);
       ...
       double avarage2 = cat(...);
    }
    This way you can reuse the function.
    7. your avarage calculation will always yield a whole number, if you add integers the result will be an integer, if you divide two integers the result is an integer as well. That integer will be cast to a double, giving a whole number. You should instead cast one of the numbers to a double:
    Code:
      double avarage = (double)sum / number;

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: C++ School Final Project

    First, sorry for not using the [code] tags... I did not know. Secondly,I do not currently know how to use arrays. My computer teacher unfortunately is not very good. I will work in your suggestions into my programming. Thanks for the help!
    Last edited by woomba; Jan 6th, 2006 at 03:51 PM. Reason: I forgot to type something in

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: C++ School Final Project

    Indeed ...

    You should not #include .cpp files. #include apstring.h and compile apstring.cpp separately, then link it with your program. (In other words, add it to the project.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: C++ School Final Project

    I took some of the advice except for using arrays since I do not know how to use them and the project is due in a very short period of time.
    Code:
     /* Daniel Gonzalez
    Start Date: 01/03/06
    Due Date: 1/11/06
    This program calculates a person's average in a class
    It works by asking the person to input the name of x number categories and how much each is worth**.
    It then asks the person to input how many grades are to be inputed under each category** */
    
    //--------------------------------------------------------------------------------------
    #include <iostream.h >
    #include <math.h>
    #include <apstring.cpp>
    //--------------------------------------------------------------------
    int cat01(double a1, double a2,double a3,double a4,double a5,double a6, double a7,double a8,double a9, double addition, double average, double y, double numgrade)
    /* Gets the average of up to 9 numbers worth x% of the grade */
    {
        cout << "Enter the amount of grades ";
        cin >> numgrade;
        y=0;
        while (numgrade >0 )
        {
        cin >> a1;
        y++;
        numgrade--;
        cin >> a2;
        y++;
        numgrade--;
        cin >> a3;
        y++;
        numgrade--;
        cin >> a4;
        y++;
        numgrade--;
        cin >> a5;
        y++;
        numgrade--;
        cin >> a6;
        y++;
        numgrade--;
        cin >> a7;
        y++;
        numgrade--;
        cin >> a8;
        y++;
        numgrade--;
        cin >> a9;
        y++;
        numgrade--;
        }
        addition= 1+2+3+4+5+6+7+8+9;
        average= (double)addition/y;
        return average;
        
        }
    //--------------------------------------------------------------------------------------
    //-------------------------------------
    int main()
    
    {
        apstring cat1;
        apstring cat2;
        apstring cat3;
        apstring cat4;
        apstring cat5;
        apstring cat6;
        apstring cat7;
        apstring cat8;
        apstring cat9;
        double numcat;
        double numper;
        double funcnum;
        double percent1;
        double percent2;
        double percent3;
        double percent4;
        double percent5;
        double percent6;
        double percent7;
        double percent8;
        double percent9;
    	double average1;
    	double average2;
    	double average3;
    	double average4;
    	double average5;
    	double average6;
    	double average7;
    	double average8;
    	double average9;
        char yn;
        do {
        cout << "Enter the amount of categories :";
        cin >> numcat;
        cout << "Enter the names of the categories : "<< endl;
        while ( numcat >0 )
        {
    
        cin >> cat1;
        numcat--;
        cin >> cat2;
        numcat--;
        cin >> cat3;
        numcat--;
        cin >> cat4;
        numcat--;
        cin >> cat5;
        numcat--;
        cin >> cat6;
        numcat--;
        cin >> cat7;
        numcat--;
        cin >> cat8;
        numcat--;
        cin >> cat9;
        numcat--;
        }
        cout << "Please re-enter the amount of categories ";
        cin >> numper;
        cout << "Enter how much of the percent is each category worth (in decimal form) : ";
        
        while (numper > 0)
        {
            cin >> percent1;
            numper--;
            cin >> percent2;
            numper--;
            cin >> percent3;
            numper--;
            cin >> percent4;
            numper--;
            cin >> percent5;
            numper--;
            cin >> percent6;
            numper--;
            cin >> percent7;
            numper--;
            cin >> percent8;
            numper--;
            cin >> percent9;
            numper--;
        }
        cout << "Please re-enter the amount of categories: ";
        cin >> funcnum;
        while (funcnum > 0) {
        average1 = cat01();
        funcnum--;
        
    }
    
        
        cout << "If you would like to continue type Y. If you would like to stop press N . ";
        cin >> yn;
        
    } while (yn == 'Y' || yn == 'y');
      if (yn == 'N' || yn == 'n')
    	cout << "Thank you for using Daniel Gonzalez's Grade Calculator!" << endl;
    	cout << "Have a nice day!" << endl;
    	return(0);
    }
    My error is that it says that cat01 has no parameters. What should i do to fix this error?

    Sorry for being such a bother
    Woomba

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: C++ School Final Project

    Code:
        average1 = cat01();
    You're calling the function without the 1052352 parameters you declared.

    By the way, your input stuff won't work the way you intend it to. It looks like you wrote the code so that you can use arrays, but then didn't, and in a very weird way, too. And making the user enter the amount of categories three (correction: three + the third value he enters) times is ridiculous - just copy the value! (You know how to assign one variable to the other, do you?)

    There are various other problems with the code, but I doubt you still have time to fix them.


    Edit: Looking at it more closely, this code is so horribly broken, it's not even funny. What happens to all the parameters you pass to cat01? What's that name supposed to mean, anyway?
    Where to begin ...?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: C++ School Final Project

    At least he's learning....

    Isnt that all we ask for...


    Then again as he stated... His teacher is a dumbass(My way of saying that he doesnt know everything.even the stuff he teaches).
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: C++ School Final Project

    Using my very rendundant method of programming, I have almost fully completed my program.If you look at my program now you could see how I have incorporated suggestsions from this forum and other into the program Currently i get no errors while compiling, but my averages are giving me weird numbers such as 1.0990e+9. If you could help me with the last aspect of my code I would be eternaly greatful
    Code:
    
    //--------------------------------------------------------------------------------------
    #include <iostream.h >
    #include <math.h>
    #include <apstring.cpp>
    //--------------------------------------------------------------------
    double cat01()
    /* Gets the average of up to 9 numbers worth x% of the grade */
    {
            double a1;
            double a2;
            double a3;
            double a4;
            double a5;
            double a6;
            double a7;
            double a8;
            double a9;
            double addition;
            double average;
            double y;
            double numgrade;
        cout << "Enter the amount of grades ";
        cin >> numgrade;
        y=0;
        
        if (numgrade >0)
        cin >> a1;
        numgrade--;
            y++;
        if (numgrade >0)
            cin >> a2;
            y++;
            numgrade--;
        if (numgrade >0)    
        cin >> a3;
            y++;
            numgrade--;
        if (numgrade >0)     
        cin >> a4;
            y++;
            numgrade--;
        if (numgrade >0)     
        cin >> a5;
            y++;
            numgrade--;
     if (numgrade >0)
            cin >> a6;
            y++;
            numgrade--;
     if (numgrade >0)
        cin >> a7;
        y++;
        numgrade--;
     if (numgrade >0)
        cin >> a8;
        y++;
        numgrade--;
     if (numgrade >0)
        cin >> a9;
        y++;
        numgrade--;
        
        addition= a1+a2+a3+a4+a5+a6+a7+a8+a9;
        average= (double)addition/y;
        return average;
        
        }
    //--------------------------------------------------------------------------------------
    
    
    
    //--------------------------------------------------------------------------------------
    int main()
    
    {
        apstring cat1;
        apstring cat2;
        apstring cat3;
        apstring cat4;
        apstring cat5;
        apstring cat6;
        apstring cat7;
        apstring cat8;
        apstring cat9;
        double numcat;
        double numcat3;
        double numcat4;
        double numcat5;
        double percent1;
        double percent2;
        double percent3;
        double percent4;
        double percent5;
        double percent6;
        double percent7;
        double percent8;
        double percent9;
        double average1=0;
        double average2=0;
        double average3=0;
        double average4=0;
        double average5=0;
        double average6=0;
        double average7=0;
        double average8=0;
        double average9=0;
        double final1;
        double final2;
        double final3;
        double final4;
        double final5;
        double final6;
        double final7;
        double final8;
        double final9;
        double ultfinaladd;
        double ultfinal;
        char yn;
    
        do {
        cout << "Enter the amount of categories :";
        cin >> numcat;
        cout << "Enter the names of the categories : "<< endl;
        
     if (numcat >0)
        cin >> cat1;
        numcat--;
     if (numcat >0)
        cin >> cat2;
        numcat--;
     if (numcat >0)
        cin >> cat3;
        numcat--;
     if (numcat >0)
        cin >> cat4;
        numcat--;
     if (numcat >0)
        cin >> cat5;
        numcat--;
     if (numcat >0)
        cin >> cat6;
        numcat--;
     if (numcat >0)
        cin >> cat7;
        numcat--;
     if (numcat >0)
        cin >> cat8;
        numcat--;
     if (numcat >0)
        cin >> cat9;
        numcat--;
        
        cout << "Please re-enter the amount of categories"<< endl;
        cin >> numcat3;
        cout << "Enter how much of the percent is each category worth (in decimal form) : ";
        
        
    if (numcat3 > 0)
            cin >> percent1;
            numcat3--;
     if (numcat3 >= 0)
            cin >> percent2;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent3;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent4;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent5;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent6;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent7;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent8;
            numcat3--;
     if (numcat3 > 0)
            cin >> percent9;
            numcat3--;
        
        cout << "Please re-enter the amount of categories"<< endl;
        cin >> numcat4;
    if (numcat4 > 0)
        average1 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average2 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average3 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average4 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average5 = cat01();
        numcat4--;
    if (numcat > 0)
        average6 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average7 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average8 = cat01();
        numcat4--;
    if (numcat4 > 0)
        average9 = cat01();
        numcat4--;
    
        
        
    
        cout << "Please re-enter the amount of categories"<< endl;
        cin >> numcat5;
    if (numcat5 > 0)
        cout << "The average of " << cat1 << " is" << average1 << endl;
        numcat5--;
    if (numcat5 > 0)
        cout << "The average of " << cat2 << " is" << average2 << endl;
        numcat5--;
    if (numcat5 > 0)
        cout << "The average of " << cat3 << " is" << average3 << endl;
        numcat5--;
    if (numcat5 > 0)
        cout << "The average of " << cat4 << " is" << average4 << endl;
        numcat5--;
    if (numcat5 > 0)
        cout << "The average of " << cat5 << " is" << average5 << endl;
        numcat5--;
    if (numcat5 > 0)
        cout << "The average of " << cat6 << " is" << average6 << endl;
        numcat5--;
    if (numcat5 > 0)
    cout << "The average of " << cat7 << " is" << average7 << endl;
    numcat5--;
    if (numcat5 > 0)
    cout << "The average of " << cat8 << " is" << average8 << endl;
    numcat5--;
    if (numcat5 > 0)
    cout << "The average of " << cat9 << " is" << average9 << endl;
    numcat5--;
    double numcat9;
    cout << "Enter the amount of categories again" << endl;
    cin >> numcat9;
    
    
    
    final1=average1*percent1;
    final2=average2*percent2;
    final3=average3*percent3;
    final4=average4*percent4;
    final5=average5*percent5;
    final6=average6*percent6;
    final7=average7*percent7;
    final8=average8*percent8;
    final9=average9*percent9;
    ultfinaladd= average1+average2+average3+average4+average5+average6+average7+average8+average9;
    ultfinal= (double)ultfinaladd/numcat9;
    cout << "Your final grade is " << ultfinal << "percent" << endl;
    if (ultfinal < 60)
       cout << "You failed!" << endl;
    else if (ultfinal < 70 && ultfinal >= 60)
         cout << "You barely passed with a D!" << endl;
    else if (ultfinal < 80 && ultfinal >= 70)
         cout << "You passed with a C!" << endl;
    else if (ultfinal < 90 && ultfinal >= 80)
         cout << "You did great with a B!" << endl;
    else if (ultfinal < 100 && ultfinal >= 90)
         cout << "You did great and got an A!" << endl;
    else if (ultfinal >= 100)
         cout << "Amazing! You got a perfect score!" << endl;
        cout << "If you would like to continue type Y. If you would like to stop press N . ";
        cin >> yn;
        
    } while (yn == 'Y' || yn == 'y');
      if (yn == 'N' || yn == 'n')
        cout << "Thank you for using Daniel Gonzalez's Grade Calculator!" << endl;
        cout << "Have a nice day!" << endl;
        return(0);
    }

    P.S. instead of repeating this course in school, I plan on taking the class at a community-college in my area. Hopefully I will receive better instruction/ learn more

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Re: C++ School Final Project

    I finally got my project to work perfectly! (Up to nine numbers in each category)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width