|
-
October 27th, 2010, 03:39 PM
#31
Re: Help wit C++
 Originally Posted by GCDEF
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
-
October 27th, 2010, 03:51 PM
#32
Re: Help wit C++
 Originally Posted by ade161
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
-
October 27th, 2010, 03:52 PM
#33
Re: Help wit C++
 Originally Posted by GCDEF
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?
-
October 27th, 2010, 04:04 PM
#34
Re: Help wit C++
 Originally Posted by GCDEF
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
-
October 28th, 2010, 07:23 AM
#35
Re: Help wit C++
 Originally Posted by ade161
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".
-
October 28th, 2010, 08:05 AM
#36
Re: Help wit C++
 Originally Posted by Ankheg
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).
-
October 28th, 2010, 08:10 AM
#37
Re: Help wit C++
 Originally Posted by Lindley
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
-
October 28th, 2010, 10:17 AM
#38
Re: Help wit C++
 Originally Posted by Ankheg
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?
-
October 28th, 2010, 10:19 AM
#39
-
October 28th, 2010, 10:20 AM
#40
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.
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
|