CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 40 of 40

Thread: Help wit C++

  1. #31
    Join Date
    Aug 2010
    Posts
    51

    Re: Help wit C++

    Quote Originally Posted by GCDEF View Post
    That'll work. Don't forget the second part of the problem.

    In addition, write a statement that invokes the calcAverage function and assigns its return value to a double variable named quotient. Use the following numbers as the actual arguments: 45.67, 8.35, 125.78, 99.56.
    double calcAverage (double, double, double, double); // prototype

    double calcAverage (45.67, 8.35, 125.78, 99.56) // invoke

    double calcAverage (double num1, double num2, double num3, double num4)
    {
    double quotient = 0.0;
    quotient = (num1 + num2 + num3 + num4) / 4;
    return quotient;
    } // end of calcAverage function

  2. #32
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Help wit C++

    Quote Originally Posted by ade161 View Post
    double calcAverage (45.67, 8.35, 125.78, 99.56) // invoke
    Close

    write a statement that invokes the calcAverage function and assigns its return value to a double variable named quotient

  3. #33
    Join Date
    Aug 2010
    Posts
    51

    Re: Help wit C++

    Quote Originally Posted by GCDEF View Post
    That'll work. Don't forget the second part of the problem.

    In addition, write a statement that invokes the calcAverage function and assigns its return value to a double variable named quotient. Use the following numbers as the actual arguments: 45.67, 8.35, 125.78, 99.56.
    7. cout<<”Enter a character”;
    cin>>response;
    char getCharacter (); // prototype
    char getCharacter (); //invoke
    {
    return custCode;
    }


    is this right?

  4. #34
    Join Date
    Aug 2010
    Posts
    51

    Re: Help wit C++

    Quote Originally Posted by GCDEF View Post
    Close

    write a statement that invokes the calcAverage function and assigns its return value to a double variable named quotient
    quotient = double calcAverage (45.67, 8.35, 125.78, 99.56) invoke

  5. #35
    Join Date
    Aug 2010
    Posts
    47

    Re: Help wit C++

    Quote Originally Posted by ade161 View Post
    quotient = double calcAverage (45.67, 8.35, 125.78, 99.56) invoke
    You're getting really close now. The only definite problem with that is that you didn't end the statement (add a ; ) and the "invoke" needs to be a comment.

    You do have another potential problem though... but it's entirely a social one. It could be assumed from the problem that the double named quotient already exists. But it could also be assumed that it doesn't. I think it would be safer if you explicitly defined quotient as a variable in your answer.

    Another suggestion I have is for your prototype. Personally I would prototype it as:
    double calcAverage (double num1, double num2, double num3, double num4);

    This has two advantages. One is that you get more detail when you read the prototype yourself (the compiler doesn't care). So someone reading your prototypes will have a better idea of what's going on (it's customary to separate out the prototypes into a header file, and people will frequently go look through that to see what functions your code has). The other is that it's actually easier to write... just cut and paste the first line of the function, and add a ; to the end.

    Technically this is optional, but I often argue that making your code readable and maintainable is just as important as making it "correct".

  6. #36
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Help wit C++

    Quote Originally Posted by Ankheg View Post
    You're getting really close now. The only definite problem with that is that you didn't end the statement (add a ; ) and the "invoke" needs to be a comment.
    There's another problem with it----when calling a function you don't specify its return type (that is already known).

  7. #37
    Join Date
    Aug 2010
    Posts
    47

    Re: Help wit C++

    Quote Originally Posted by Lindley View Post
    There's another problem with it----when calling a function you don't specify its return type (that is already known).
    Hah, I didn't even see that. Good catch.

    - Brent

  8. #38
    Join Date
    Aug 2010
    Posts
    51

    Re: Help wit C++

    Quote Originally Posted by Ankheg View Post
    Hah, I didn't even see that. Good catch.

    - Brent
    7. cout<<”Enter a character”;
    cin>>response;
    char getCharacter (); // prototype
    char getCharacter (); //invoke
    {
    return custCode;
    }


    is this right?

  9. #39
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Help wit C++

    You need to revisit the basics of function usage.

    http://lmgtfy.com/?q=call+a+function+C&#37;2B%2B&l=1

  10. #40
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Help wit C++

    You know... a lot of the issues here you would be able to solve on your own probably faster if only you installed a C++ compiler and made actual programs.

    There's lots of free compilers out there, iirc there's even programs that allow you to just enter snippets of code (like the ones you need here) and that take care of all of the surrounding details on their own.

Page 3 of 3 FirstFirst 123

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

Featured