Like Tree1Likes

C++ program in need of help!?

This is a discussion on C++ program in need of help!? within the C++ Programming forums, part of the General Programming Boards category; I am supposed to use arrays to create a program that removes the lowest number and highest number. Than it ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    7

    C++ program in need of help!?

    I am supposed to use arrays to create a program that removes the lowest number and highest number. Than it needs to add the rest but I can't even get my program to run.
    The user needs to enter 8 scores:9.2,9.3,9.0,9.9,9.5,9.5,9.6,9.8.
    the output should be:
    contestant recieves: 56.90
    Dropped low score: 9.00
    Dropped High Score: 9.90


    Any help to fix these errors will be appreciated. I'm not good at C++.
    Code:
     10 F:\Program6-Arrays2.0.cpp expected init-declarator before "int" 
    10 F:\Program6-Arrays2.0.cpp expected `,' or `;' before "int" 
     F:\Program6-Arrays2.0.cpp In function `void getinput(int*, int)': 
    33 F:\Program6-Arrays2.0.cpp `num' undeclared (first use this function) 
      (Each undeclared identifier is reported only once for each function it appears in.) 
    35 F:\Program6-Arrays2.0.cpp `counter' undeclared (first use this function) 
    38 F:\Program6-Arrays2.0.cpp `score' undeclared (first use this function) 
    39 F:\Program6-Arrays2.0.cpp `sum' undeclared (first use this function) 
     F:\Program6-Arrays2.0.cpp In function `int getlow(int*, int)': 
    49 F:\Program6-Arrays2.0.cpp `numbers' undeclared (first use this function) 
    50 F:\Program6-Arrays2.0.cpp `SIZE' undeclared (first use this function) 
    59 F:\Program6-Arrays2.0.cpp a function-definition is not allowed here before '{' token 
    59 F:\Program6-Arrays2.0.cpp expected `,' or `;' before '{' token 
    86 F:\Program6-Arrays2.0.cpp expected `}' at end of input

    CODE:
    Code:
    #include<iostream>
    #include<cmath>
    #include<conio.h>
    #include<iomanip> //needed for setw()
    using namespace std;
    // Function prototypes
    int getlow(int[],int)
    int gethigh(int[],int)
    double getsum(int[],int)
    void getinput(int[],int)
    void showoutput(int[],int)
    int main()
    {
        int getlow,gethigh,numbers[SIZE];
        double getsum,scores;
        const int SIZE = 50;
    void getinput(int[],int)
    int getlow(int[],int)
    int gethigh(int[],int)
    double getsum(int[],int)
    void showoutput(int[],int)
        
    }
    void getinput(int[],int)
    {
         
    cout << "Enter number of Judges Scores:";
    cin >> num;
    while (counter <= num )
    {   
      cout << "Enter Judges Score #" <<counter << ":";
      cin >> score;
      sum+=score;
      counter++;
    }
    }
    int getlow(int[],int limit)
    {
        int  count;
        int lowest;
        
        lowest = numbers[0];
        for (count = 1; count < SIZE; count++)
        {
            if (numbers[count]<lowest)
               lowest = numbers[count];
    }
        
        
    int gethigh(int[],int)
    {
        int count;
        int highest;
        
        highest=numbers[0];
        for(count=1;count<SIZE;count++)
    {
        if(numbers[count]> highest)
        highest=numbers[count];
    }
    double getsum(int[],int)
    {
           double scores;
           
           scores+=score
           scores-=lowest
           scores-=highest
    }
    void output[int[],int]
    {
         cout<<setprecision(1)<<fixed<<showpoint;
         cout<<"Contestant Receives: "<<scores<<endl;
         cout<<"Dropped Low Score: "<<lowest<<endl;
         cout<<"Dropped High Score: "<<highest<<endl;
    system("pause");
    }

  2. #2
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    You should definitely revise function declaration, definition, and usage. Also, proper code formatting.
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    7

    New code

    My new code. still doesn't work
    Code:
    #include<iostream>
    #include<cmath>
    #include<conio.h>
    #include<iomanip> //needed for setw()
    using namespace std;
    // Function prototypes
    int getlow(int[],int);
    int gethigh(int[],int);
    double getsum(int[],int);
    void getinput(int[],int);
    void showoutput(int[],int);
    int main()
    {
        int getlow,gethigh, numbers[SIZE];
        double getsum,scores,num,sum,counter,score;
    void getinput(int[],int);
    int getlow(int[],int);
    int gethigh(int[],int);
    double getsum(int[],int);
    void showoutput(int[],int);
        
    }
    void getinput(int[],int)
    {
         
    cout << "Enter number of Judges Scores:";
    cin >> num;
    while (counter <= num )
    {   
      cout << "Enter Judges Score #" <<counter << ":";
      cin >> score;
      sum+=score;
      counter++;
    }
    }
    int getlow(int[],int limit)
    {
        int  count;
        int lowest;
        
        lowest = numbers[0];
        for (count = 1; count < SIZE; count++)
        {
            if (numbers[count]<lowest)
               lowest = numbers[count];
    }
        
        
    int gethigh(int[],int)
    {
        int count;
        int highest;
        
        highest=numbers[0];
        for(count=1;count<SIZE;count++)
    {
        if(numbers[count]> highest)
        highest=numbers[count];
    }
    double getsum(int[],int)
    {
           double scores;
           
           scores+=score
           scores-=lowest
           scores-=highest
    }
    void output(int[],int)
    {
         cout<<setprecision(1)<<fixed<<showpoint;
         cout<<"Contestant Receives: "<<scores<<endl;
         cout<<"Dropped Low Score: "<<lowest<<endl;
         cout<<"Dropped High Score: "<<highest<<endl;
    system("pause");
    }

  4. #4
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Okay, first of all, "doesn't work" is not even close to an error description.

    Second of all: What are you doing inside main()? Take a close look at how you're trying to call your functions and compare that to your textbook / lecture script / whatever.

    Thirdly, you are not exchanging any data between your functions. Whatever they do, it will be lost after they finish working.
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    And fix that indentation already!!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Quote Originally Posted by Elysia View Post
    And fix that indentation already!!
    IMO, indentation is roughly ok, except it's not consistent; however, missing spaces between the different blocks seems worse to me.
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Yet another cross-poster.

  8. #8
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Oh, and your compiler might wonder what "SIZE" is meant to be.
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  9. #9
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Quote Originally Posted by rags_to_riches View Post
    Yet another cross-poster.
    Least "she" seems to also get "cross-posting answers".
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  10. #10
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Ok, so I'm going to try and help you get started, try and read through this simplified version of your code and see if you can understand how the function call works.

    Best of luck (I'm pretty new to C++ but I've been programming off and on (more off than on!) since 1977... Indentation etc. is personal choice unless you are working with a team (to an agreed format).

    Code:
    #include<iostream>
    using namespace std;
    
    
    // Declare Function:
    int getinput(); // getinput function - returns an Int.
    
    
    int main(){
    
        int result = 0; // declare and sets an Int.
    
        result = getinput();// Calls the getinput function and assigns the 
                                   // value of the returned int to "result".
    
        cout << endl << "The Total score was " << result << endl; // printout.
    }
    
    
    // This is the function
    int getinput(){
    
        int counter=0, Iscore =0, Tscore =0; // declare and set ints.
        cout << "Enter number of Judges: ";
        cin >> counter;
    
        while (counter > 0 ){ // counts down No. of Judges - loops till zero
            cout << "Enter Judges Score #" <<counter << ": ";
            cin >> Iscore; // collects individual Judges score
            Tscore += Iscore; // adds it to total score
            counter--; // decreases counter value by 1
            }
    
        return (Tscore); // Returns the value of total score.
    }
    Last edited by Brian_of_Bozeat; 12-06-2011 at 07:50 AM.

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Quote Originally Posted by Brian_of_Bozeat View Post
    ...Indentation etc. is personal choice unless you are working with a team (to an agreed format).
    Yes, it is highly subjective. However, there usually are a set of defined minimum required (that are implicitly defined) that a programmer should adhere to.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Quote Originally Posted by Elysia View Post
    Yes, it is highly subjective. However, there usually are a set of defined minimum required (that are implicitly defined) that a programmer should adhere to.
    It would be more helpful if you linked to a tutorial? - Just putting people down for not following YOUR rules does not help. Ironically, your English is appalling.

  13. #13
    language hopper dennis.cpp's Avatar
    Join Date
    Jan 2011
    Location
    Herborn, Hesse, Germany
    Posts
    197
    Easy guys! I just wanted to make clear how hard it is for us to try and help if the code sample given is so difficult to read (which it is if all the blocks are put next to each other without any spacing). Surely I didn't want to start a fight over coding style best practices!
    Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
    Operating system: Fedora 19 (64-Bit) / Linux 3.11.6-200.fc19 / KDE SC 4.11.2
    Compiler: gcc 4.8.2 with Netbeans IDE 7.4

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Quote Originally Posted by Brian_of_Bozeat View Post
    It would be more helpful if you linked to a tutorial? - Just putting people down for not following YOUR rules does not help. Ironically, your English is appalling.
    How about Googling? That should set a good minimum standard.
    It is also not about my rules, but about generally accepted rules.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Nov 2011
    Posts
    7

    ?

    Quote Originally Posted by dennis.cpp View Post
    Least "she" seems to also get "cross-posting answers".
    Is is bad to cross-post? I just want to get as much input as I can to better my knowledge in C++.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2009, 03:47 PM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 12:11 PM
  5. making a program leave a msg for background program when it closes
    By superflygizmo in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2006, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21