Homework Help

I know how you guys detest people asking homework questions so I apologize in advance if I offend anyone! I just need someone to take a look at my project and point out what in my code would give me some random jumble of information for the average...

Anyone have any ideas???? I'd appreciate any pointers!!

Thanks!
Liz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream> 

using namespace std ;

double Average(double *Numbers)

{ 												// Function Command
	int Count = 0;   
	double Sums = 0;
  	double Average = 0;  

	for (Count = 0; Count <10; Count++)
		Sums = Sums + Numbers[Count];
	
	Average = Sums / Count;
	return (Average);
}

	
int main()
{
												// declare variables
	double Numbers[10];                         
	double Sums;                       
	int Count; 									
 
	for (Count = 0; Count <10; Count++)			// User Input
	{
		cout << "Enter a rational number: ";
		cin >> Numbers[Count];
	}
	cout << endl;
											      // Call functions
	double Average(double Numbers[]);			  // Determine the average 
		
	cout << Average << " is your average." << endl;
	cout << endl;

	cin.get();
	cin.get();
	return 0;                                    // Terminate
}


Try replacing Line 34 with:
 
double avg = Average( Numbers );


and Line 36 with:
 
cout << avg << " is your average." << endl;


NOTES:
1. Average() is a function as defined from Lines 5-17
2. You can declare, define, or call a function. You can even get the address to a function (what you did on your original Line 36). In other words, what you thought was a jumble was probably the address to your Average() function rather than the result of an Average() function call.

Make sure you understand how to do all that is in 2. clearly.

Feel free to ask questions - we just don't like people asking us to do their homework for them!

Last edited on

use the rand() function.


** Its not about homework questions, its about when people just post the problem without giving it a try.
Also you want to avoid calling everything Average (for function name on Line 5 and local variable on Line 10) - that can cause you some confusion.

@writetonsharma - hehehe...
use the rand() function.

...that's an interesting read on what Liz was asking for, but I understand what you are getting at.
kfmfe04


our replies clashed and I didn't notice that. yeah, i read the problem and from initial code i thought he wants the rand() function..damn I just saw... :(

anyway.. hehehe..Thanks.. :D

Last edited on
Thanks guys; it is fixed now! I knew I was missing something beteen my function variable and my call in the main function but couldn't pinpoint it. Ahhh, if only I had your skills!

You guys rock!

Thanks!!
Liz
I knew I was missing something beteen my function variable and my call in the main function but couldn't pinpoint it.


That's the smart way to figure out what's wrong - you need to break down your program and isolate where you think your problem is.

Make sure you learn how to use a debugger in your class (ask your teacher about it if you do not have a chance to learn it) - it will save you countless hours of frustration and guessing around. GL.
Topic archived. No new replies allowed.