2016-04-26 6 views
-1

Я не понимаю, почему это ожидаемые ошибки первичного исключения есть !!! ...:ожидаемое первичное выражение перед 'arrayName'

Running /home/ubuntu/workspace/sample.cpp 
/home/ubuntu/workspace/sample.cpp: In function ‘int main()’: 
/home/ubuntu/workspace/sample.cpp:50:22: error: expected primary-expression before ‘arrayHelpfull’ 
      std::string arrayHelpfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:51:10: error: expected primary-expression before ‘double’ 
      double arrayHelpfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:52:22: error: expected primary-expression before ‘arrayNone’ 
      std::string arrayNone[3], 
        ^
/home/ubuntu/workspace/sample.cpp:53:10: error: expected primary-expression before ‘double’ 
      double arrayNonePoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:54:23: error: expected primary-expression before ‘arrayHarmfull’ 
      std::string arrayHarmfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:55:11: error: expected primary-expression before ‘double’ 
      double arrayHarmfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:61:20: error: expected primary-expression before ‘arrayHelpfull’ 
     std::string arrayHelpfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:62:8: error: expected primary-expression before ‘double’ 
     double arrayHelpfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:63:20: error: expected primary-expression before ‘arrayNone’ 
     std::string arrayNone[3], 
        ^
/home/ubuntu/workspace/sample.cpp:64:8: error: expected primary-expression before ‘double’ 
     double arrayNonePoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:65:21: error: expected primary-expression before ‘arrayHarmfull’ 
     std::string arrayHarmfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:66:9: error: expected primary-expression before ‘double’ 
     double arrayHarmfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:74:20: error: expected primary-expression before ‘arrayHelpfull’ 
     std::string arrayHelpfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:75:8: error: expected primary-expression before ‘double’ 
     double arrayHelpfullPoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:76:20: error: expected primary-expression before ‘arrayNone’ 
     std::string arrayNone[3], 
        ^
/home/ubuntu/workspace/sample.cpp:77:8: error: expected primary-expression before ‘double’ 
     double arrayNonePoints[3], 
     ^
/home/ubuntu/workspace/sample.cpp:78:21: error: expected primary-expression before ‘arrayHarmfull’ 
     std::string arrayHarmfull[3], 
        ^
/home/ubuntu/workspace/sample.cpp:79:9: error: expected primary-expression before ‘double’ 
     double arrayHarmfullPoints[3], 
     ^

Код:

#include<iostream> 
#include<string> 
#include<fstream> 


void printingItems(


    std::string arrayHelpfull[3], 
    double arrayHelpfullPoints[3], 
    std::string arrayNone[3], 
    double arrayNonePoints[3], 
    std::string arrayHarmfull[3], 
    double arrayHarmfullPoints[3], 
    std::string option 

    ) { 
    std::cout << option << std::endl; 

} 


int main(){ 
    std::string arrayHelpfull[3] = {"fruits", "soda" , "candy"}; 
    double arrayHelpfullPoints[3] = {20.4,50.2,30.0}; 

    std::string arrayNone[3] = {"chair", "shoe" , "pencil"}; 
    double arrayNonePoints[3] = {0,0,0}; 

    std::string arrayHarmfull[3] = {"meth", "dirtyneedle","ninga"}; 
    double arrayHarmfullPoints[3] = {-20,-50,-30}; 

    int userChoice = 0; 
    while (userChoice != 4) { 

     std::cout << "1 - Just Plain Items" 
      << std::endl 
      << "2 - Helpfull Items" 
      << std::endl 
      << "3 - Harmfull Items" 
      << std::endl 
      << "4 - Quit" 
      << std::endl; 

     std::cin >> userChoice; 

     switch (userChoice) { 
     case 1: 
      printingItems(
      std::string arrayHelpfull[3], 
      double arrayHelpfullPoints[3], 
      std::string arrayNone[3], 
      double arrayNonePoints[3], 
      std::string arrayHarmfull[3], 
      double arrayHarmfullPoints[3], 
      "Plain" 
     ); 
      break; 
     case 2: 
     printingItems(
     std::string arrayHelpfull[3], 
     double arrayHelpfullPoints[3], 
     std::string arrayNone[3], 
     double arrayNonePoints[3], 
     std::string arrayHarmfull[3], 
     double arrayHarmfullPoints[3], 
     "Helpfull" 
     ); 

      break; 
     case 3: 

     printingItems(
     std::string arrayHelpfull[3], 
     double arrayHelpfullPoints[3], 
     std::string arrayNone[3], 
     double arrayNonePoints[3], 
     std::string arrayHarmfull[3], 
     double arrayHarmfullPoints[3], 
     "Harmfull" 
     ); 

      break; 
     } 


    } 
} 
+0

Вам нужно [mcve] и вопрос. – juanchopanza

+0

Почему вы используете ',' после каждого объявления переменной в 'printingItems', а не'; '? – computerfreaker

+0

@computerfreaker Это список параметров функции. – NathanOliver

ответ

1
printingItems(
      std::string arrayHelpfull[3], 
      double arrayHelpfullPoints[3], 
      std::string arrayNone[3], 
      double arrayNonePoints[3], 
      std::string arrayHarmfull[3], 
      double arrayHarmfullPoints[3], 
      "Plain" 
     ); 

не так, как вы вызываете функцию и передать переменные к нему. Вам просто нужно указать имя переменной для функции. То, что вы делаете, заключается в попытке переопределить переменные в вызове функции. Все ваши вызовы функций должны выглядеть так:

printingItems(arrayHelpfull, arrayHelpfullPoints, arrayNone, 
       arrayNonePoints, arrayHarmfull, arrayHarmfullPoints, "Plain"); 

Вам также необходимо использовать некоторый согласованный отступ. Имея отступы, что изменения делают код очень трудным для чтения.

+0

Omg Большое спасибо! Ничего себе, отвлекся! не могу принять в 7мин – amanuel2

Смежные вопросы