Thread: Really Lost - Functions

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    2

    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. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    How much C++ do you know?

    Have you checked out the tutorials?

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

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2
    Quote Originally Posted by robwhit View Post
    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. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    If that's your attitude, then yes, you're going to fail.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by nexja View Post
    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. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    We can help you with question if you have them.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by nexja View Post
    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.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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.


    Quote 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.
    Last edited by DougDbug; 12-05-2007 at 02:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newb question about interpreting and writing functions
    By crazychile in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 07:51 PM
  2. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  3. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 06:53 PM
  4. Variables do not equal functions!!!
    By me@burk. in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 06:24 AM
  5. inheritance & virtual functions
    By xagiber in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2002, 12:10 PM