Thread: C++ program in need of help!?

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    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).
    Clear indentation is critical to code clarity. Since you are sharing your code and expecting others to read it, it's more than just a personal choice. There is more than one way to clearly indent code, but it needs to be clear where each scope is by the indentation.

    If for whatever reason your code has sloppy indentation, you should fix it when posting it for others to read.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #17
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    Thank you for all the input it has really helped with my code. I have been working on it today and have minimalized my errors. Sadly, I still have a few errors left I can't figure out how to solve.
    Code:
     F:\Program6-Arrays2.8.cpp In function `void getInput(int, int)':
    47 F:\Program6-Arrays2.8.cpp invalid types `int[int]' for array subscript
     F:\Program6-Arrays2.8.cpp In function `double getLow(double*, int)':
    72 F:\Program6-Arrays2.8.cpp name lookup of `counter' changed for new ISO `for' scoping
    57 F:\Program6-Arrays2.8.cpp   using obsolete binding at `counter'
    Code:
    #include<iostream>
    #include<cmath>
    #include<conio.h>
    #include<iomanip> //needed for setw()
    
    using namespace std;
    
    // Function prototypes
    
    void getInput(int,int);
    double getLow(double[],int);
    double getHigh(double[],int);
    double getsum(double[],int);
    
    int main()
    {
        const int SIZE=8;
        int num,numbers;
        double sum,lowestscore,highestscore,scores[SIZE];
    
    cout << setprecision(1) << fixed << showpoint;
    
    getInput(numbers,SIZE);
    
    lowestscore = getLow (scores,SIZE);
    
    highestscore = getHigh (scores,SIZE);
    
    
    sum = getsum (scores,SIZE);
    
    sum -= lowestscore;
    
    sum -= highestscore;
        
    cout << "Contestant Receives: " << sum << endl;
    
    cout << "Dropped Low Score: " << lowestscore << endl;
    
    cout << "Dropped High Score: " << highestscore << endl;
    
    system("pause");
    
        
        
    }
    void getInput(int numbers,int size)
    {
         int index;
         
         for(index = 0; index <= size - 1;index++)
         {
     
      cout << "Enter Judges Score #" << (index+1) << ":";
      cin >> numbers[index];
    }
    }
    double getLow(double array[], int size)
    {
           double lowest;
           
           lowest = array[0];
           
    for(int counter = 1; counter < size ; counter++)
    {
            if( array [counter] < lowest)
                lowest = array [counter];
    return lowest;
    }
        
        
    double getHigh( double array[] , int size);
    {
        double highest;
        
        highest = array[0];
        for(counter = 1; counter < size ; counter++)
    {
        if(array [counter] > highest)
        highest = array [counter];
        
        return highest;
    }
    double getsum(double array[],int size);
    {
           double sum=0;
           for(int count = 0 ;count < size ;count++)
           sum += array [count];
           
           return sum;
    }
    }
    }
    Last edited by chinesebarbie; 12-06-2011 at 03:14 PM.

  3. #18
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    chinesebarbie - your getinput function still has no return value as it is a void function. Please re-read the code I wrote earlier and try to understand how values are passed in it before modifying yours again.


    As for:
    Quote Originally Posted by King Mir View Post
    Clear indentation is critical to code clarity. Since you are sharing your code and expecting others to read it, it's more than just a personal choice. There is more than one way to clearly indent code, but it needs to be clear where each scope is by the indentation. If for whatever reason your code has sloppy indentation, you should fix it when posting it for others to read.
    No matter how right you are - The OP is clearly a complete novice, please give him a chance to get his code working before slapping him down over the niceties of whitespace conventions, his code isn't that hard to read! A polite suggestion at the end of the thread (after helping him) would be a better approach than diving in half way through with criticism.

  4. #19
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Also - have a look at this tutorial and numbers 10 and 11 that follow it. They will help you to understand what I was trying to tell you. Best of luck.

    C++ - 9 - Functions

  5. #20
    Registered User
    Join Date
    Nov 2011
    Posts
    7
    Brain_of_Bozeat - Thanks, for the link. I spent the last couple hours watching videos ,and I think I have a better understanding of what you where trying to tell me.

    My new question is can you convert a double variable into a double array?

  6. #21
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I've personally noticed that when code posted on here has very poor formatting that it is the direct cause of the problem about 50% of the time.

    In this instance I can yet again see that it is the direct cause of a compilation error.

    I wonder how much time an automatic first response that asked the poster to first indent their code properly would save...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #22
    Registered User
    Join Date
    Nov 2011
    Location
    Bozeat, Northants. UK
    Posts
    23
    Quote Originally Posted by chinesebarbie View Post
    Brain_of_Bozeat - Thanks, for the link. I spent the last couple hours watching videos ,and I think I have a better understanding of what you where trying to tell me.

    My new question is can you convert a double variable into a double array?
    I'm not sure that I understand what you are trying to do now. Please explain clearly what you are trying to do and why and I will try to help.
    (it may be that you need to watch more of bucky's videos).

  8. #23
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by iMalc View Post
    I've personally noticed that when code posted on here has very poor formatting that it is the direct cause of the problem about 50% of the time.
    Yes..but the OP refuses to try fixing it ..
    Code:
    for(int counter = 1; counter < size ; counter++)
    {
            if( array [counter] < lowest)
                lowest = array [counter];
    return lowest;
    }

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manasij7479 View Post
    Yes..but the OP refuses to try fixing it ..
    Code:
    for(int counter = 1; counter < size ; counter++)
    {
            if( array [counter] < lowest)
                lowest = array [counter];
    return lowest;
    }
    Then we can simply stop helping!
    Indentation is basics of basics, and also a sort of etiquette. You don't go around asking people to do certain things.
    If you ask someone to wash your clothes, you can at least make sure they don't stink!
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2009, 04: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, 01: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, 07:44 PM