Solved

Calling Functions

Posted on 2000-04-19
4
178 Views
Last Modified: 2010-04-02
What is the right way to call a function in a program?
0
Comment
Question by:SBuntin
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 2731978
you use the functin name a left parenthises, then any parameters, then a right parenthesis.

example follows.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2731985
// no parameters.
int GetZero()
{
   return 0;
}

// 1 parameter.
int Increment(int i)
{
   return i +1;
};

// 2 parameters.
int Add(int x,int y)
{
   return x + y;
};

     *    *    *

int x = GetZero();
int y = Increment(x);
int z = Add(x,y);

Let me know if you have any questions.
0
 

Author Comment

by:SBuntin
ID: 2735885
I am having problems linking or something...I really don't know what it is saying...

Here is my problem whats wrong:

#include <iostream.h>
#include <math.h>

void DegreesToRadians();
void RadiansToDegrees();

int main()
{
      int convert;
      int degree, radian;


      cout << "What would you like to convert to?\n";
      cout << "1. Degrees to Radians";
      cout << "2. Radians to Degrees";
      cin >> convert;

      if (convert == 1)
      {
            // Input
            cout << "Degrees? ";
            cin >> degree;

            // Calculations and Output
            DegreesToRadians();
      }

      if (convert == 2)
      {
            // Input
            cout << "Radians? ";
            cin >> radian;

            // Calculations and Output
            RadiansToDegrees();


      }


return 0;
}




float DegreesToRadians(float degree)
{
  float pi = 22 / 7;
  float totalb = degree * (pi/180);

  return totalb;
}

float RadiansToDegrees(float radian)
{
      float pi = 22 / 7;
      float totalB = radian * (180/pi);

      return totalB;
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 2742552
The forward declarations of the 2 conversion functions do not match the function definitions.  Both the definitions take floats as parrameters and return floats as return values.  but your forward definitions take no parameters and return no values.  You should change them to

float DegreesToRadians(float);
float RadiansToDegrees(float);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now