# Thread: Really Lost - Functions

1. ## Really Lost - Functions

Listen, I know you're not supposed to expect over the top help as in someone basically writing the whole program for you but I am really lost and I am going to fail if I don't get this program finished. I have no idea what I'm doing as I've been lost the whole semester. I promise if anyone can help me get this done or help me learn or anything, I will pay you 20 dollars as that's all I have or if you can at least help me I will greatly appreciate it, I'm very stressed. Here is my assignment and I keep trying and trying but I have no idea what I'm doing:

Write a program to calculate the average of three test scores. The program must use the following function prototypes (do not change them):

int getScores ( int &, int &, int & );
Function prompts the user to enter 4 test scores.
int findLowest ( int, int, int, int );
Function identifies the lowest score
void calcAvg ( float &, int, int, int );
Function calculates the average of the 3 highest scores.
void displayAvg ( float );
Display the average with 1 decimal position.

All functions will be called by main.

2. How much C++ do you know?

Have you checked out the tutorials?

http://www.cprogramming.com/tutorial.html

3. Originally Posted by robwhit
How much C++ do you know?

Have you checked out the tutorials?

http://www.cprogramming.com/tutorial.html
I don't know, I don't even know if I can be helped now. I guess I'm just gonna fail the course.

4. If that's your attitude, then yes, you're going to fail.

5. Originally Posted by nexja
I don't know, I don't even know if I can be helped now. I guess I'm just gonna fail the course.
maybe so, but at least you'll have your insanity.

Do you know how to get input from the user using cin?
Do you know how to output stuff using cout?

6. Sorry, but even if we DID write the code for you, you would still fail since it wasn't you who wrote the code.
You'll get the same trouble later on anyway. If you simply haven't been able to keep up, I suggest you re-apply for the course and try to learn everything properly.

7. Write a program to calculate the average of three test scores. The program must use the following function prototypes (do not change them):

int getScores ( int &, int &, int & );
Function prompts the user to enter 4 test scores.
int findLowest ( int, int, int, int );
Function identifies the lowest score
void calcAvg ( float &, int, int, int );
Function calculates the average of the 3 highest scores.
void displayAvg ( float );
Display the average with 1 decimal position.

All functions will be called by main.
To answer this question, you probably need to know how to use functions and references along with basic input/output such as cin and cout, and other simple stuff such as comparison operators (to calculate the minimum of some numbers) and arithmetic operators (to calculate the average of some numbers).

I suggest you pick up your programming textbox (you know, the one that cracks when you open it), and read the first few chapters until you can understand and write programs like
Code:
```#include <iostream>

using namespace std;

int main() {
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
int average = (a + b) / 2;
cout << "The average of " << a << " and " << b << " is " << average << endl;
return 0;
}```
Then read about functions and references, either in a textbox or in online tutorials.

8. Originally Posted by nexja
I don't know, I don't even know if I can be helped now. I guess I'm just gonna fail the course.
"The man who believes he will succeed and the man who believes he will fail shall both prove themselves right". A good attitude is a necessary start, don't sabotage yourself by assuming failure before you begin.

That said, do you know how to:

* Read numbers from the user
* Compare numbers to find which is greater
* Do simple math (addition, division) on numbers
* Print strings and numbers

?

Those are the 4 key components to the program you're asked to make. If you can do those four, you can do the program. If you need help on those four, ask about which part specifically, or if you don't see how to compose those four into a program.

9. Programmng is difficult, and most programming classes move quickly. You've really got to understand the basics (variables, loops, if-statements, functions, etc.). And, programming requires more "homework time" than the average class. I suspect many of your classmates have spent many hours on this assignment.

Originally Posted by DougDbug

DEVELOP YOUR CODE A FEW LINES AT A TIME!!!

It seems like a lot of instructors don't really teach how to approach a programming problem. This result in lots of frustrated beginners & students. Nobody... not even experienced programmers write the whole program before trying it out!

1- Start-out with a 'Hello World" type program. You can substitute "Hello World" with some better description of the program.

2- Add one or two lines of code at a time. Compile, test-run, and debug before adding more lines.

3- Add some extra cout statements so you can "see" what the program is doing, and confirm that it's working, before you're completely done. (You can take them out, or coment them out later.)

4- When you create a function, make an empty (do-nothing) function first. Make the function prototype, the empty function definition, and the function call. Then, test-compile. If your function needs to return a value, just make it return a constant (i.e. return 10; ). It's also helpful to put a cout statement in your do-nothing function like: cout << "In GetDistance() function \n"; .

...Now, this isn't as easy as it sounds, because you can't just write line one, then line two, then line three, of your code. (It won't compile if you do that.) The trick (the fun part, actually) is figuring-out which part of code makes sense to work on next.

Compilers can easily get confused when threre's an error (or two). Sometimes they will point to the wrong line. Sometimes one real error will cause the compiler to report several errors. Link errors are even trickier to track down.

So, it really helps to test-run and test-compile after every one or two lines. As you gain experience, you can write whole functions before testing. But, as you gain experience your programs generally will get longer and more complex, so you still won't be writing the whole program before testing & debugging.
In this case, you might want to start-out with the example dwks gave you. Just add one feature at a time until your program meets all of the assigned requirements. (i.e. You can modify the example to take 3 scores. Then, move the average calculation into a function. Then, move the cout statement into a function, etc...)

I'm sure you know how to do some of the things required by the assignment. Start-out with whatever you know how to do, then work on the harder parts.

I hope some of these posts will help you to get started. If you get stuck, and you can't find the answer in your book, notes, or in the tutorial, come back, show us what you have so far, and ask a more specific question. We probably aren't going to give you (or sell) you a direct answer or a complete working program, but we can give you lots of hints, tips, and suggestions.