• Advertisement
Sign in to follow this  

Small Calculator Errors

This topic is 4174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright well tonight I have been working on getting my "calculator" up and running. But everytime I compile it gives me the following errors: too many arguments to function: float addition It gives me those for all the functions besides main.
// my first program in C++

#include <iostream> 
using namespace std;

float addition ()
{
      // Declaring Variables:
  float additionnumberone, additionnumbertwo, additionsum;
  
  cout << "Please enter the first number to add:\n";
  cin >> additionnumberone;
  cout << "Please enter the second number to add:\n";
  cin >> additionnumbertwo;
  cout << "The result is:\n";
  additionsum = (additionnumberone + additionnumbertwo);
  cout << additionsum;
  cin.get();
  return (additionsum);
}

float subtraction ()
{
      // Declaring Variables:
  float subtractionnumberone, subtractionnumbertwo, subtractionsum;
  
  cout << "Please enter the first number to subtract:\n";
  cin >> subtractionnumberone;
  cout << "Please enter the second number to subtract:\n";
  cin >> subtractionnumbertwo;
  cout << "The result is:\n";
  subtractionsum = (subtractionnumberone - subtractionnumbertwo);
  cout << subtractionsum;
  cin.get();
  return (subtractionsum);
}

float multiplication ()
{
      // Declaring Variables:
  float multiplicationnumberone, multiplicationnumbertwo, multiplicationsum;
  
  cout << "Please enter the first number to multiply:\n";
  cin >> multiplicationnumberone;
  cout << "Please enter the second number to multiply:\n";
  cin >> multiplicationnumbertwo;
  cout << "The result is:\n";
  multiplicationsum = (multiplicationnumberone * multiplicationnumbertwo);
  cout << multiplicationsum;
  cin.get();
  return (multiplicationsum);
}

float division ()
{
      // Declaring Variables:
  float divisionnumberone, divisionnumbertwo, divisionsum;
  
  cout << "Please enter the first number to divide:\n";
  cin >> divisionnumberone;
  cout << "Please enter the second number to divide by:\n";
  cin >> divisionnumbertwo;
  cout << "The result is:\n";
  divisionsum = (divisionnumberone / divisionnumbertwo);
  cout << divisionsum;
  cin.get();
  return (divisionsum);
}


int main ()
{
      // Declaring Variables:
  float choice, finalresult;
  
  cout << "Please choose an option\n";
  cout << "(1) Addition\n";
  cout << "(2) Subtraction\n";
  cout << "(3) Multiplication\n";
  cout << "(4) Division\n";
  cin >> choice;
if( choice == 1 )
       addition (0, 0, 0);
else if ( choice == 2 )
       subtraction(0, 0, 0);
else if ( choice == 3 )
       multiplication(0, 0, 0);
else if ( choice == 4 )
       division(0, 0, 0);
else 
  cout << "I am sorry that is not a menu choice.  Please choose again:\n";
  cin >> choice;
  cout << "The result is:\n "; finalresult;
  cin.get();
  return 0;
}

Does anyone have any ideas as to what is going on?

Share this post


Link to post
Share on other sites
Advertisement
Because when you wrote the function prototype you told it not to accept any variables.

float addition ()
{


But when you call it in main you are passing it three variables

addition (0, 0, 0);


Since you are asking for input inside the function addition, all you need to change is when you call addition, pass it no variables


addition();


Same goes for the other functions as well

Share this post


Link to post
Share on other sites
Dead on! I did that quick fix, and my calculator is now running great! (Excluding the horrible interface. :) )

What would you suggest the next step up from calculator is? Tic-Tac-Toe, or is that a bit too advanced yet? Does TTT involve pointers?

Share this post


Link to post
Share on other sites
TicTacToe is probably within your reach. I believe all it really requires is an understanding of arrays. It'll probably be more fun then writing a calc app since you get to play with an AI too =) .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement