Results 1 to 5 of 5
  1. #1
    disturbed14x's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    Candyland
    Posts
    115
    Reputation
    44
    Thanks
    15
    My Mood
    Bored

    help with program please

    Code:
    #including<iostream>
    using namespace std;
    
    int array[10]={3,5,2,7,8,4,6,7,4,11};
    
    int findMax()
    {
            int length=array.length();
            int max;
            int count;
    
             for(int i=0;i<length;i++)
             {
                      count+=1
                      if(array[i]>max)
                            max=array[i];
              }
              return max;
    }
    int main()
    {
             findMax(array[10]);
    }

    a) create a function to find the position of the max value in the array
    b) in your main function create and initialize an array, then call this findMax function to display the position of the maximum value in the array and display this value based on the position information.

    I am lost and i cant figure out what i should be doing if anyone would help.
    Last edited by Mayion; 11-15-2014 at 07:52 AM.
    FX6100@4.5GHz (NH-D14)
    Gigabyte GA-970A-d3
    G.skill Ripsaw X series 8GB
    Thermaltake 700w
    MSI GTX 670

    I7-3960x@4.2GHz
    EVGA X79 SLI
    G.skill Ripsaw X series 8GB
    Thermaltake 700w
    Zotac GTX 970
    https://www.youtube.com/user/l3igwill1994 MY YOUTUBE!!!@!@!@!@!@! you should subscribe........

  2. #2
    ERGaergaergaergaergearg's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    172
    Reputation
    19
    Thanks
    30
    My Mood
    Amazed
    First of all would appreciate if you posted your code in [CODE] tags. Would be alot easier to read.

    Here's a working code, hopefully this is what you needed help with.
    Read the comments in the code for explanations.

    Code:
    int findMax() {
    
    	int length = (sizeof(array) / sizeof(int)); // Initialized a variable to get the size of the array[]
    	int max = 0; // Initilized max, if you use an uninitialized variable you'll get an error
    
    	for (int i = 0; i < length; i++) {
    
    		if (array[i] > max) { // Checked if the current array number is bigger than 0
    			max = array[i]; // If True, change value of max to the current number in array
    		}
    
    	}
    	return max; // Return the biggest number in array[]
    
    }
    Hopefully this made it more clear, if there were something you didn't understand. Feel free to ask more.

    Bai

  3. The Following User Says Thank You to ERGaergaergaergaergearg For This Useful Post:

    disturbed14x (11-07-2014)

  4. #3
    disturbed14x's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    Candyland
    Posts
    115
    Reputation
    44
    Thanks
    15
    My Mood
    Bored
    Quote Originally Posted by gresan6 View Post
    First of all would appreciate if you posted your code in [CODE] tags. Would be alot easier to read.

    Here's a working code, hopefully this is what you needed help with.
    Read the comments in the code for explanations.

    Code:
    int findMax() {
    
        int length = (sizeof(array) / sizeof(int)); // Initialized a variable to get the size of the array[]
        int max = 0; // Initilized max, if you use an uninitialized variable you'll get an error
    
        for (int i = 0; i < length; i++) {
    
            if (array[i] > max) { // Checked if the current array number is bigger than 0
                max = array[i]; // If True, change value of max to the current number in array
            }
    
        }
        return max; // Return the biggest number in array[]
    
    }
    Hopefully this made it more clear, if there were something you didn't understand. Feel free to ask more.

    Bai
    i'm still a little confused i can understand for the most part how to do the max function, but i keep messing with it because i need to have a separate function called main and i need to call the function in order to solve the max problem for the array in the main functions.
    FX6100@4.5GHz (NH-D14)
    Gigabyte GA-970A-d3
    G.skill Ripsaw X series 8GB
    Thermaltake 700w
    MSI GTX 670

    I7-3960x@4.2GHz
    EVGA X79 SLI
    G.skill Ripsaw X series 8GB
    Thermaltake 700w
    Zotac GTX 970
    https://www.youtube.com/user/l3igwill1994 MY YOUTUBE!!!@!@!@!@!@! you should subscribe........

  5. #4
    ERGaergaergaergaergearg's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    172
    Reputation
    19
    Thanks
    30
    My Mood
    Amazed
    Quote Originally Posted by disturbed14x View Post
    i'm still a little confused i can understand for the most part how to do the max function, but i keep messing with it because i need to have a separate function called main and i need to call the function in order to solve the max problem for the array in the main functions.
    Well, if that's the case. You need to pass the array[] and length variable from main() to the function by parameter.

    Code:
    #include <iostream>>
    
    using namespace std;
    
    int findMax(int array[], int length);
    
    int main() {
    	
    	int array[10] = { 3, 5, 2, 7, 8, 4, 6, 7, 4, 11 };
    	int length = (sizeof(array) / sizeof(int)); // Getting the size of the array
    
    	int maxNum = findMax(array, length); // Since the function returns a variable, you need something to hold the variable
    					 // Passed the array[] and length variable as argument to the function
    
    	cout << maxNum << endl; // Display the max value returned
    
    	return 0;
    }
    
    int findMax(int array[], int length) { // Pass an array and a length variable as parameter
    	
    	int max = 0;
    
    	for (int i = 0; i < length; i++) {
    
    		if (array[i] > max) {
    			max = array[i];
    		}
    
    	}
    	return max;
    }
    Bai
    Last edited by ERGaergaergaergaergearg; 11-07-2014 at 11:28 AM.

  6. The Following User Says Thank You to ERGaergaergaergaergearg For This Useful Post:

    disturbed14x (11-07-2014)

  7. #5
    Mayion's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Location
    Bed
    Posts
    13,502
    Reputation
    4018
    Thanks
    8,368
    My Mood
    Twisted
    No response from OP since a week ago so I assume it's solved.
    I do not use any type of messenger outside of MPGH.
    Inactive but you can reach me through VM/PM.










     

    Donator - 30 August 2013
    Battlefield Minion - 26 October 2013

    Blackshot Minion - 14 January 2014/16 September 2014
    Minecraft Minion - 7 February 2014/16 September 2014
    WarRock Minion - 23 February 2014
    League of Legends Minion - 21 March 2014

    Minion+ - 15 May 2014
    Other Semi-Popular First Person Shooter Minion - 8 August 2014
    CrossFire Minion - 23 October 2014
    Programming Section Minion - 13 November 2014
    Marketplace Minion - 7 December 2014

    Official Middleman - 7 December 2014 - 27 June 2015
    Moderator - 29 December 2014
    Project Blackout Minion - 10 January 2015
    News Force Interviewer - January 2015
    Steam Games Minion - 21 March 2015
    Dragon Nest Minion - 31 March 2015
    Publicist - April 2015 - 21 September 2015
    Global Moderator - 25 August 2015
    Super User - 13 August 2016



Similar Threads

  1. [Help Request] Help With Coding Please :)
    By str999 in forum Crossfire Coding Help & Discussion
    Replies: 0
    Last Post: 03-13-2014, 12:50 PM
  2. [Help Request] Help With Hacks Please
    By Kevstarz99 in forum CrossFire Help
    Replies: 2
    Last Post: 07-23-2013, 04:40 PM
  3. [Help Request] help with chams?? please
    By ursine in forum Combat Arms Coding Help & Discussion
    Replies: 2
    Last Post: 07-18-2013, 01:25 PM
  4. Help with programming (please see inside)
    By hobosrock696 in forum C++/C Programming
    Replies: 4
    Last Post: 10-20-2010, 03:23 PM
  5. Help With Coding Please
    By pbguy145 in forum WarRock - International Hacks
    Replies: 1
    Last Post: 10-10-2007, 06:52 PM