我的程序无法编译
My programm cannot compile
$ 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);
^
请帮帮我。 上面的错误是我得到的。
/*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);
}
由于 c++ 源文件是从上到下编译的,因此在what_do_you_want_to_do
中使用之前不会声明arbitrage_two_diff_odds(a, b, c);
。
要修复此声明arbitrage_two_diff_odds(a,b,c(;就在what_do_you_want_to_do
之前.
正如@Eduard所说arbitrage_two_diff_odds(a, b, c)
仅在使用后声明,因此编译器不知道此函数。您应该在使用之前声明它。
通过将行double arbitrage_two_diff_odds(double a, double b, double c)
放在 main 或使用它的函数之前,在使用函数之前声明函数(通常函数的定义放在#include
和全局变量声明之后。
您可以将实现保留在原处。
下次请正确缩进代码。这是一团糟,否则其他人很难理解。
/*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);
}
相关文章:
- 如何从测试脚本中运行WAF编译C++程序?
- 如何使用命令提示符、记事本和 MinGW 使用主文件、头文件和实现文件编译C++程序?
- 在Yocto上本地构建和编译C / C++程序
- 我无法在代码块中编译c ++程序。它给了我错误
- 在 turbo c++ 中使用 TCC 从 cmd 编译C++程序
- 如何在Linux中编译C 程序以生成Windows可执行文件
- 在Python中编译C 程序时,请尝试捕获OS错误
- 在Windows命令提示符中使用G 编译C 程序
- 如何使用HDF5源代码编译c程序
- 如何在Mac终端中编译C ++程序
- 设置 VS 代码以编译C++程序
- 无法在 Ubuntu 上编译 c++ 程序
- 无法使用 libcurl 库编译 c++ 程序
- 编译C 程序,该程序将SFML与MINGW一起到端口,从Linux到Windows
- 编译C 程序时具有逻辑错误,该程序应将任意大的数字表示为字符串
- 如何在 Windows 命令提示符下使用 Dev C++ 编译器编译 c++ 程序
- 在cygwin中使用mingw编译器编译c ++程序时缺少dll。
- 无法在Windows上编写的Linux上编译C程序
- 架构的未定义符号x86_64惠姆使用G 编译C 程序
- 指定netbeans用来编译C++程序的完整编译命令