0
votes
    #include <iostream>
    using namespace std; 
    
    //defining function
    double distance(double,double);
    int main() {
      
        //where im having issues i think
        cout << distance();
    
        return 0; 
    }
    //attempting to start the function with rate*time=distance and returning the value
    double distance(double rate, double time)
    {
        time = 10; 
        rate = 10; 
        return time*rate; 
    }

main.cpp:9:11: error: no matching function for call to 'distance' cout << distance(); ^~~~~~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_iterator_base_funcs.h:138:5: note: candidate function template not viable: requires 2 arguments, but 0 were provided distance(_InputIterator __first, _InputIterator __last) ^ main.cpp:5:8: note: candidate function not viable: requires 2 arguments, but 0 were provided double distance(double,double); ^ 1 error generated. compiler exit status 1

this is what i got when i attempted to run it through. i understand this is pretty rudimentary but I'd like to have an understanding of what I did wrong before I continue

2
You need to give two parameters in your call to the function; like, say, cout << distance(5.0, 10.0); . - Adrian Mole
@Unslander Monica I don't know? Maybe I'm a beginner with minimal understanding? Crazy concept I know. - rei

2 Answers

7
votes

You should pass arguments to the function because you've defined as: double distance(double, double);

So, the solution would be:

#include <iostream>
using namespace std;    

double distance(double, double);

int main() 
{
   cout << distance(10, 10);
   return 0;
}

double distance(double rate, double time)
{
   return time * rate;
}

Also, it would be better to use std:: before everything that's part of the standard library of C++, instead of typing using namespace std; at the top of your code.

Read more: Why is "using namespace std;" considered bad practice?

0
votes

At least pass the parameters when you are calling the function since your function needs to params