-5
$ g++ -o arbitrage arbitrage_sportsbetting_calc.cpp
arbitrage_sportsbetting_calc.cpp: In function ‘double what_do_you_want_to_do(int)’:
arbitrage_sportsbetting_calc.cpp:24:34: error: ‘arbitrage_two_diff_odds’ was not declared in this scope
   arbitrage_two_diff_odds(a, b, c);
                                  ^

Please help me out. the above error is what am getting.

 /*Programm for making decision on arbitrage betting*/



#include <iostream>
//using namespace ::std;

//Prompting user to select an option.

double what_do_you_want_to_do(int z){
double a, b, c;
std::cout << "What do you want to do" << std::endl;
std::cout << "For calculating Percentage & Profit for a single bet, PRES 1" << std::endl;
std::cout << "For calculating Arbitrage Percentantage & Profit for two odds, PRESS 2" << std::endl;
std::cout << "For calculating Arbitrage Percentantage & Profit for three odds, PRESS 3" << std::endl;
std::cin  >> z;

//Using switch to branch.
switch(z)
 {
    case 1:
    //call function 1
    break;
    case 2:
    //call function 2
    if (z == 2)
    arbitrage_two_diff_odds(a, b, c);
    break;
    case 3:
    //call function 3
    break;
 }
}

 //function for calculation of the arbitrage for two different odds.
 double arbitrage_two_diff_odds(double a, double b, double c){

 //Prompting user for imput.
std::cout << "Enter your values in this format \"1st odd, 2nd odd, investment\": ";
std::cin  >> a >> b >> c;

//Calculating the sum of the percentage of the two different odds.
double diff_two_odds = ((1/a)*100) + ((1/b)*100);

//maniplation
if (diff_two_odds <= 90)
{
    double calc_profit = c/diff_two_odds;
    double idividual_bet1 = (c*((1/a)*100))/diff_two_odds;
    double idividual_bet2 = (c*((1/b)*100))/diff_two_odds;
    std::cout << "The arbitrage odds you put in are "<<a<< "and"<<b<<"."<< std::endl;
    std::cout << "The percentage gain for individual odd are "<<((1/a)*100)<<"% and "<<((1/b)*100)<<"% respectively."<<std::endl;
    std::cout << "The individual bet for your propose investment are "<<idividual_bet1<<"$ for "<<a<< "and "<<idividual_bet2<<"$ for "
    <<b<< "respectively, which equals "<<c<<"."<<std::endl;
    std::cout << "From your proposed investment of "<<c<<"$, Your arbitrage profit is "<<calc_profit<< std::endl;       
}
else
    std::cout << "No profit for the odds entered, try different one again"<< std::endl;
    std::cout << "No profit for the odds entered, try different one again"<< std::endl;

}

 int main()

{

int z = what_do_you_want_to_do(z);

}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Paschal
  • 19
  • 1
  • 8
  • 4
    The error is quite clear: You haven't declare the `arbitrage_two_diff_odds` function before you attempt to call it. Remember that in C++ you have to declare everything before you use it. – Some programmer dude May 23 '18 at 07:47
  • 2
    For future questions please don't spam with unrelated tags. That will only cause people to not want to help you. Please read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), and [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/) for how to write good questions. And also please read http://idownvotedbecau.se/ to learn what you should not do. – Some programmer dude May 23 '18 at 07:49
  • forward declare your arbitrage_two_diff_odds() function or rearrange the order of functions – JeJo May 23 '18 at 07:50
  • In other words, change the order of the functions or forward declare them : https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c#4757718 – Robert Andrzejuk May 23 '18 at 07:51
  • 1
    @Paschal Please read [ask]. The title of the question is extremely uninformative if nothing else. – dandan78 May 23 '18 at 07:54
  • 1
    Possible duplicate of [What are forward declarations in C++?](https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c) – Toby Speight May 23 '18 at 10:54

2 Answers2

2

As c++ source files are compile from top to bottom, arbitrage_two_diff_odds(a, b, c); is not declared before it is used in what_do_you_want_to_do.
To fix this declare arbitrage_two_diff_odds(a, b, c); just before the what_do_you_want_to_do.

Eduard Rostomyan
  • 7,050
  • 2
  • 37
  • 76
  • A function only needs to be **declared** before it can be used. Though in this case, the simplest solution is just to reorder things. – BoBTFish May 23 '18 at 07:52
0

As @Eduard said arbitrage_two_diff_odds(a, b, c) is declared only after the usage so the compiler does not know about this function. You should declare it before the usage.

Declare the function before the usage by putting the line double arbitrage_two_diff_odds(double a, double b, double c) before the main or the function where you use it (generally definitions of functions are put after the #include and the global variable declarations.

You can leave implementation where it is.

Please indent your code properly next time. It is a mess and difficult to understand for other people otherwise.

/*Programm for making decision on arbitrage betting*/

#include <iostream>
//using namespace ::std;


//functions declaration generally goes here
double arbitrage_two_diff_odds(double a, double b, double c); //<-----MISSING LINE


//Prompting user to select an option.

double what_do_you_want_to_do(int z){
  double a, b, c;
  std::cout << "What do you want to do" << std::endl;
  std::cout << "For calculating Percentage & Profit for a single bet, PRES 1" << std::endl;
  std::cout << "For calculating Arbitrage Percentantage & Profit for two odds, PRESS 2" << std::endl;
  std::cout << "For calculating Arbitrage Percentantage & Profit for three odds, PRESS 3" << std::endl;
  std::cin  >> z;

  //Using switch to branch.
  switch(z)
  {
    case 1:
    //call function 1
    break;
    case 2:
    //call function 2
    if (z == 2)
    arbitrage_two_diff_odds(a, b, c);
    break;
    case 3:
    //call function 3
    break;
  }
}

//function for calculation of the arbitrage for two different odds.
double arbitrage_two_diff_odds(double a, double b, double c){

  //Prompting user for imput.
  std::cout << "Enter your values in this format \"1st odd, 2nd odd, investment\": ";
  std::cin  >> a >> b >> c;

  //Calculating the sum of the percentage of the two different odds.
  double diff_two_odds = ((1/a)*100) + ((1/b)*100);

  //maniplation
  if (diff_two_odds <= 90)
  {
    double calc_profit = c/diff_two_odds;
    double idividual_bet1 = (c*((1/a)*100))/diff_two_odds;
    double idividual_bet2 = (c*((1/b)*100))/diff_two_odds;
    std::cout << "The arbitrage odds you put in are "<<a<< "and"<<b<<"."<< std::endl;
    std::cout << "The percentage gain for individual odd are "<<((1/a)*100)<<"% and "<<((1/b)*100)<<"% respectively."<<std::endl;
    std::cout << "The individual bet for your propose investment are "<<idividual_bet1<<"$ for "<<a<< "and "<<idividual_bet2<<"$ for "
    <<b<< "respectively, which equals "<<c<<"."<<std::endl;
    std::cout << "From your proposed investment of "<<c<<"$, Your arbitrage profit is "<<calc_profit<< std::endl;
  }
  else
  std::cout << "No profit for the odds entered, try different one again"<< std::endl;
  std::cout << "No profit for the odds entered, try different one again"<< std::endl;

}

int main()

{

  int z = what_do_you_want_to_do(z);

}
roschach
  • 8,390
  • 14
  • 74
  • 124