7 Replies - 682 Views - Last Post: 12 January 2009 - 07:43 AM Rate Topic: -----

#1 Viper99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 04-January 09

Unable to get rid of errors

Post icon  Posted 11 January 2009 - 11:30 PM

One error & I still don't even know if it works properly???



// calculate the average of three test scores.

#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;

using std::cout;
using std::cin;
using std::endl;

double getTestScore (); 
double calcAverage (double testScore1, double testScore2, double testScore3);

int main()
{
double testScore1 = 0.0;
double testScore2 = 0.0;
double testScore3 = 0.0;
double average = 0.0;
double test1 = 0.0;
double test2 = 0.0;
double test3 = 0.0;

average = calcAverage (testScore1, testScore2, testScore3);
testScore1 = getTestScore ();
testScore2 = getTestScore ();
testScore3 = getTestScore ();

average = calcAverage (testScore1 + testScore2 + testScore3) / 3;
cout << "Average Score : " << getTestScore() << endl;

return 0;
}

double calcAverage (int testScore1, int testScore2, int testScore3)
{
double average = 0.0;
average = (testScore1 + testScore2 + testScore3) / 3;
return average;
}

double getTestScore (int test1, int test2, int test3)
{
cout << "Enter First Test Score : ";
cin >> test1;
cout << "Enter Second Test Score : ";
cin >> test2;
cout << "Enter Third Test Score : ";
cin >> test3;
return (test1 + test2 + test3) / 3;
}




Error

Line

average = calcAverage (testScore1 + testScore2 + testScore3) / 3;

error C2660: 'calcAverage' : function does not take 1 arguments


Any insight, I have been working on this program all night. I hope it works fine it is due tommorrow.

Viper99

Is This A Good Question/Topic? 0
  • +

Replies To: Unable to get rid of errors

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Unable to get rid of errors

Posted 11 January 2009 - 11:35 PM

Please post you code examples using code tags:

:code:

average = calcAverage (testScore1 + testScore2 + testScore3) / 3;


error C2660: 'calcAverage' : function does not take 1 arguments

calcAverage (testScore1 + testScore2 + testScore3)

has one argument - the sum of the three variables.
Was This Post Helpful? 0
  • +
  • -

#3 Viper99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 04-January 09

Re: Unable to get rid of errors

Posted 11 January 2009 - 11:45 PM

View Postn8wxs, on 11 Jan, 2009 - 10:35 PM, said:

Please post you code examples using code tags:

:code:

average = calcAverage (testScore1 + testScore2 + testScore3) / 3;


error C2660: 'calcAverage' : function does not take 1 arguments

calcAverage (testScore1 + testScore2 + testScore3)

has one argument - the sum of the three variables.



What?
Can't you add three variables???
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4316
  • View blog
  • Posts: 12,096
  • Joined: 18-April 07

Re: Unable to get rid of errors

Posted 11 January 2009 - 11:49 PM

You can add the three variables but what we are saying is that they add together to form one result value which you are then passing to calcAverage. But you have created calcAverage to take in three parameters.

So instead of adding the three together and using calcAverage on the sum, you have to pass the three variables separated by commas.

//wrong
average = calcAverage (testScore1 + testScore2 + testScore3) / 3;

//right
average = calcAverage (testScore1, testScore2, testScore3);



You also don't want to divide the result of calcAverage by 3 , that is what you do in calcAverage to find the average. Here we pass the three variable to the function, you find the average and then return the average into a variable called "average"

Hope that makes things clear enough now.

"At DIC we be average calculating code ninjas... in our spare time we also calculate interstellar objects like the sun, moon, venus and perhaps KYA's big ego" :snap:
Was This Post Helpful? 0
  • +
  • -

#5 Viper99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 04-January 09

Re: Unable to get rid of errors

Posted 12 January 2009 - 12:01 AM

View PostMartyr2, on 11 Jan, 2009 - 10:49 PM, said:

You can add the three variables but what we are saying is that they add together to form one result value which you are then passing to calcAverage. But you have created calcAverage to take in three parameters.

So instead of adding the three together and using calcAverage on the sum, you have to pass the three variables separated by commas.

//wrong
average = calcAverage (testScore1 + testScore2 + testScore3) / 3;

//right
average = calcAverage (testScore1, testScore2, testScore3);



You also don't want to divide the result of calcAverage by 3 , that is what you do in calcAverage to find the average. Here we pass the three variable to the function, you find the average and then return the average into a variable called "average"

Hope that makes things clear enough now.

"At DIC we be average calculating code ninjas... in our spare time we also calculate interstellar objects like the sun, moon, venus and perhaps KYA's big ego" :snap:



When I changed this I received more errors, but I can't get rid of thie one.

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

On this line od code

calcAverage (double testScore1, double testScore2, double testScore3);




viper99
Was This Post Helpful? 0
  • +
  • -

#6 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4316
  • View blog
  • Posts: 12,096
  • Joined: 18-April 07

Re: Unable to get rid of errors

Posted 12 January 2009 - 12:13 AM

You have your prototype defined like this...

double calcAverage (double testScore1, double testScore2, double testScore3);



Then you define the function below that like this...

double calcAverage (int testScore1, int testScore2, int testScore3)
{
     // Statements
}



See a problem here? Notice that your prototype does not match your function. You have doubles up top and integers at the bottom.

Your prototype is correct since testScore1, testScore2 and testScore3 are all doubles. So be sure to change your "int" in the function to doubles...

// Correct
double calcAverage (double testScore1, double testScore2, double testScore3)
{
     // Statements
}



I can't stress this enough, listen to your errors and double click the error messages and it should take you to where in the code is the problem. Make sure that all data types match up.

;)
Was This Post Helpful? 0
  • +
  • -

#7 Viper99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 04-January 09

Re: Unable to get rid of errors

Posted 12 January 2009 - 07:34 AM

View PostMartyr2, on 11 Jan, 2009 - 11:13 PM, said:

You have your prototype defined like this...

double calcAverage (double testScore1, double testScore2, double testScore3);



Then you define the function below that like this...

double calcAverage (int testScore1, int testScore2, int testScore3)
{
     // Statements
}



See a problem here? Notice that your prototype does not match your function. You have doubles up top and integers at the bottom.

Your prototype is correct since testScore1, testScore2 and testScore3 are all doubles. So be sure to change your "int" in the function to doubles...

// Correct
double calcAverage (double testScore1, double testScore2, double testScore3)
{
     // Statements
}



I can't stress this enough, listen to your errors and double click the error messages and it should take you to where in the code is the problem. Make sure that all data types match up.

;)


I am having a heck of a time with this problem.
I do believe it is a double variable issue?
Hopefully someone can help me...


[error]

error C2660: 'getTestScore' : function does not take 1 arguments

[error]

the errors are for these three lines of code

[code]
testScore1 = getTestScore (num1);
testScore2 = getTestScore (num2);
testScore3 = getTestScore (num3);
[code]


Here is the uptodate code with errors

[code]

#include "stdafx.h"
#include <iostream>
#include <cmath>


using std::cout;
using std::cin;
using std::endl;
using namespace std;

// Function Prototype

double getTestScore (double num1, double num2, double num3);
double calcAverage (double testScore1, double testScore2, double testScore3);

int main()
{
// Declare Variables

double testScore1 = 0.0;
double testScore2 = 0.0;
double testScore3 = 0.0;
double average = 0.0;
double num1 = 0.0;
double num2 = 0.0;
double num3 = 0.0;

// Function To Calculate Average

// average = calcAverage (testScore1, testScore2, testScore3);
testScore1 = getTestScore (num1);
testScore2 = getTestScore (num2);
testScore3 = getTestScore (num3);

average = calcAverage (testScore1, testScore2, testScore3);

cout << "Average Score : " "<< getTestScore()" << average << endl;

return 0;
}
//end of main function

//calcAverage Function
double calcAverage (double testScore1, double testScore2, double testScore3)
{
double average = 0.0;
average = (testScore1 + testScore2 + testScore3) / 3;
return average;
}
//End of calcAverage

//getTestScore Function
double getTestScore (double num1, double num2, double num3)
{
cout << "Enter First Test Score : ";
cin >> num1;
cout << "Enter Second Test Score : ";
cin >> num2;
cout << "Enter Third Test Score : ";
cin >> num3;
return (num1 + num2 + num3) / 3;
}
// End of getTestScore

[code]
Was This Post Helpful? 0
  • +
  • -

#8 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Unable to get rid of errors

Posted 12 January 2009 - 07:43 AM

Compare your function definition with how you're calling the function. It's defined as taking 3 parameters, and you're calling it 3 times with 1 parameter each time.

edit: spelling corrections

This post has been edited by MorphiusFaydal: 12 January 2009 - 07:44 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1