This is my first time posting here and hopefully I'm doing it correctly. If not, my apologies. I noticed the "Do Not: Copy/Paste your homework assignment", but I'm not sure how else to explain my problem. Just so you know I'm not expecting anyone to do my assignment, just guide me. It should be a simple exercise, but I've been working on it for hours and have not been able to figure it out.
First is the assignment and then my code. There are no errors, but the program does not do what it should. Instead of cleaning the code up, I thought it might be helpful if you can see the different things that I tried and commented out.
Hopefully someone will help point me in the right direction. I have 28 hours to finish and submit it.
Brian
----------
Write the C++ code for a function that receives four double numbers. The function should calculate the average of the four numbers and then return the result. Name the function calcAverage. Name the formal parameters num1, num2, num3, and num4. Also write an appropriate function prototype for the calcAverage function. 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, and 99.56.
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
//function prototype
double calcAverage(double, double, double, double);
int main()
{
//declare variables
double quotient = 0.0;
double num1 = 0.0;
double num2 = 0.0;
double num3 = 0.0;
double num4 = 0.0;
//call function to get the character
//quotient = calcAverage(45.67, 8.35, 125.78, 99.56 / 4);
//display the quotient
cout << "quotient: " << quotient << endl;
system("pause");
return 0;
} //end of main function
//*****function definitions*****
double calcAverage(double num1, double num2, double num3, double num4, double quotient)
{
//double num1 = 45.67, num2 = 8.35, num3 = 125.78, num4 = 99.56, quotient = 0.0;
//double num1, num2, num3, num4, quotient = 0.0;
//double quotient = 0.0;
//quotient = calcAverage(45.67, 8.35, 125.78, 99.56);
quotient = (45.67 * 8.35 * 125.78 * 99.56)/4;
//quotient = num1 * num2 * num3 * num4;
return quotient;
} //end getCharacter function

New Topic/Question
Reply




MultiQuote






|