|
-
Oct 28th, 2004, 09:29 PM
#1
Thread Starter
Member
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.
-
Oct 29th, 2004, 12:36 AM
#2
Thread Starter
Member
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.
-
Oct 29th, 2004, 03:07 PM
#3
Frenzied Member
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

-
Oct 29th, 2004, 03:10 PM
#4
Software Eng.
Show us what you have so far
-
Oct 29th, 2004, 03:37 PM
#5
Thread Starter
Member
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.
-
Oct 29th, 2004, 03:38 PM
#6
Thread Starter
Member
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.
-
Oct 30th, 2004, 12:36 AM
#7
Fanatic Member
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.
-
Nov 10th, 2004, 07:03 PM
#8
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|