Results 1 to 8 of 8

Thread: Array Problems

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    I live in Oregon, U.S.A.
    Posts
    41

    Exclamation Array Problems

    Ok, I spent some time working on these, but I can't seem to think like a programmer yet. Could someone plz reply on how I would solve these problems?

    Here are the problems.

    1. Given an int num[max]
    (we allready know the average)

    Find and show the number closest to the average.

    ex. 10, 6, 9, 10, 12 It would show 6 and 9, sence the average is 7.

    2. Write the code that will find the average, then show the average and all of the numbers above the average.

    ex. 10, 6, 9, 10, 12 It would show 7, 9, 10, 10, 12 but not the 6 because it is less than the average.

    Plz help, this is for my computer science class, and it's due tomarow, and I can't seem to figure these 2 out.
    I'm a noobie when it comes to programming, please teach me, so I can also have the advantages of making my own programs, and money.

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    I live in Oregon, U.S.A.
    Posts
    41
    could you guys please hurry, I'm kinda in a rush... (got to turn this in tomarrow)
    I'm a noobie when it comes to programming, please teach me, so I can also have the advantages of making my own programs, and money.

  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I dont think anyone is going to do your homework. If you have some questions or problems I am sure we can point you in the right direction.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Show us what you have so far

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    I live in Oregon, U.S.A.
    Posts
    41
    This isnt the entire assignment.... Oh well. Here is what I have so far.

    Code:
    // Problem 2
    
    #include <iostream.h>
    
    void main()
    {
    	int num[5];
    	int MAX = 5;
    
    	for (int i2 = 0; i2 < MAX; i2++)
    	{
    		cout << "Input Scores " << i2 + 1 << "  ";
    		cin >> num[i2];
    	}
    
    	for (int a=0; a < MAX; a++)
    	{
    		int AVG[a] = 0;
    		for (int i = 1; i < MAX; i++)
    		{
    			AVG[a] = AVG[a] + num[i];
    		}
    
    	AVG[a] = AVG[a] / MAX;
    	}
    
    	for(int b = 0; b < MAX; b++)
    	{
    
    		if (num[b] > AVG)
    			cout << num[b];
    		
    	}
    	
    
    }
    I'm a noobie when it comes to programming, please teach me, so I can also have the advantages of making my own programs, and money.

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    I live in Oregon, U.S.A.
    Posts
    41
    when I do this, I get 4 errors... can anyone help me?
    I'm a noobie when it comes to programming, please teach me, so I can also have the advantages of making my own programs, and money.

  7. #7
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    Originally posted by shishkabob
    [B]This isnt the entire assignment.... Oh well. Here is what I have so far.

    Code:
    // Problem 2
    
    #include <iostream.h> // Standard is <iostream>.
    
    // using std::cout;
    // using std::cin;
    
    void main() // It's int main() not void.
    {
    	int num[5];
    	int MAX = 5; // It's const int if we define constant variable.
    
    	for (int i2 = 0; i2 < MAX; i2++)
    	{
    		cout << "Input Scores " << i2 + 1 << "  ";
    		cin >> num[i2];
    	}
    
    	for (int a=0; a < MAX; a++)
    	{
    		int AVG[a] = 0; // AVG is in the scope of this loop.
    		for (int i = 1; i < MAX; i++)
    		{
    			AVG[a] = AVG[a] + num[i];
    		}
    
    	AVG[a] = AVG[a] / MAX;
    	}
    
    	for(int b = 0; b < MAX; b++)
    	{
    
    		if (num[b] > AVG) // AVG is not accessible here. Remember, you define it inside the second loop. And AVG is an array.
    			cout << num;
    		
    	}
    
    // return 0;
    	
    
    }
    
    
    Hope this helps.

  8. #8
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Originally posted by shishkabob
    could you guys please hurry, I'm kinda in a rush... (got to turn this in tomarrow)
    Hahaha, good lord. That is hillarious.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


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