我的程序无法编译

时间:2018-05-23 07:44:43

标签: c++

MariaDB [sandbox]> CREATE TABLE test_duplicate_join
    -> (
    -> vendor INT,
    -> buyside INT,
    -> columnnme VARCHAR(32),
    -> mappingid INT ,
    -> columntype VARCHAR(32)
    -> );
Query OK, 0 rows affected (0.20 sec)

MariaDB [sandbox]> ALTER TABLE test_duplicate_join ADD PRIMARY KEY(mappingId);
Query OK, 0 rows affected (0.37 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [sandbox]> ALTER TABLE test_duplicate_join
    -> MODIFY mappingId INT NOT NULL AUTO_INCREMENT;
Query OK, 0 rows affected (0.47 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [sandbox]> CREATE UNIQUE INDEX idx_name_phone ON test_duplicate_join(vendor,buyside,columnnme,columntype);
Query OK, 0 rows affected (0.14 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [sandbox]>
MariaDB [sandbox]> INSERT INTO test_duplicate_join (vendor,buyside,columntype)
    -> VALUES  (0,34,'Excel'),(0,35,'A');
Query OK, 2 rows affected (0.03 sec)
Records: 2  Duplicates: 0  Warnings: 0

MariaDB [sandbox]>
MariaDB [sandbox]> INSERT INTO test_duplicate_join (vendor,buyside,columntype)
    -> VALUES  (0,34,'Excel'),(0,36,'fd');
Query OK, 2 rows affected (0.04 sec)
Records: 2  Duplicates: 0  Warnings: 0

MariaDB [sandbox]>
MariaDB [sandbox]> select * from test_duplicate_join;
+--------+---------+-----------+-----------+------------+
| vendor | buyside | columnnme | mappingId | columntype |
+--------+---------+-----------+-----------+------------+
|      0 |      34 | NULL      |         1 | Excel      |
|      0 |      34 | NULL      |         3 | Excel      |
|      0 |      35 | NULL      |         2 | A          |
|      0 |      36 | NULL      |         4 | fd         |
+--------+---------+-----------+-----------+------------+
4 rows in set (0.00 sec)

请帮帮我。上面的错误是我得到的。

$ 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);
                                  ^

2 个答案:

答案 0 :(得分:2)

由于c ++源文件是从上到下编译的,arbitrage_two_diff_odds(a, b, c);what_do_you_want_to_do中使用之前未声明{。}}。 要解决此问题,请声明arbitrage_two_diff_odds(a,b,c);就在what_do_you_want_to_do之前。

答案 1 :(得分:0)

正如@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);

}