-5

I'm trying to pull individual values from an array and put them into text, but keep running into errors with syntax.

#include <iostream>
#include <ostream>
using namespace std;
// PV, PM, FUE, RAP, PRE, SAB, ESP
int luch_bas [7] = {6,3,5,3,2,1,2};

int main ()
{ cout << "Tiene los atributos siguientes: \n";
  cout << "Puntos de Vida (PV)... " luch_bas[0] "\n";
  cout << "Puntos de Magia (PM)..." luch_bas[1] "\n";
  cout << "Fuerza (FUE) ..." luch_bas[2] "\n";
  cout << "Rapidez (RAP) ..." luch_bas[3] "\n";
  cout << "Precisión (PRE) ..." luch_bas[4] "\n";
  cout << "Sabiduría (SAB) ..." luch_bas[5] "\n";
  cout << "Espíritu (ESP) ..." luch_bas[6] "\n";
}

The error log I keep getting is "expected ';' before 'luch_bas'", but I'm not exactly sure where the missing ; is supposed to go? I'm sure there's a much better way to code this; I am still learning.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • 4
    You're outputting incorrectly: it should be `cout << "something" << luch_bas[N] << '\n';` – ForceBru Mar 30 '16 at 17:46
  • 1
    You need to start over from the beginning if you don't know how to output variables to streams, almost all books and tutorials have that as one of their earliest examples. [See e.g. here for a good list of beginners books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Some programmer dude Mar 30 '16 at 17:50

4 Answers4

3

try this

  int main ()
    { cout << "Tiene los atributos siguientes: \n";
      cout << "Puntos de Vida (PV)... \t" << luch_bas[0]<< "\n";
     ...
    }
Samer
  • 1,923
  • 3
  • 34
  • 54
2

The error log I keep getting is "expected ';' before 'luch_bas'", but I'm not exactly sure where the missing ; is supposed to go?

You don't wan't to put a ; as the error message suggests. You want to chain the output operator calls respectively.

The std::ostream& operator<<(std::ostream& os, Type t) returns a std::ostream& reference as you can see.

The correct way is to chain the operator<<() calls:

 cout << "Puntos de Vida (PV)... " << luch_bas[0] << "\n";
                                // ^^             ^^
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
0

It should be:

cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " << luch_bas[0] << endl;
cout << "Puntos de Magia (PM)..." << luch_bas[1] << endl;
cout << "Fuerza (FUE) ..."        << luch_bas[2] << endl;
cout << "Rapidez (RAP) ..."       << luch_bas[3] << endl;
cout << "Precisión (PRE) ..."     << luch_bas[4] << endl;
cout << "Sabiduría (SAB) ..."     << luch_bas[5] << endl;
cout << "Espíritu (ESP) ..."      << luch_bas[6] << endl;
DimChtz
  • 4,043
  • 2
  • 21
  • 39
0

use more "streaming" operators

#include <iostream>
#include <ostream>
using namespace std;
// PV, PM, FUE, RAP, PRE, SAB, ESP
int luch_bas [7] = {6,3,5,3,2,1,2};

int main ()
{ cout << "Tiene los atributos siguientes: \n";
  cout << "Puntos de Vida (PV)... " << luch_bas[0] << "\n";
  cout << "Puntos de Magia (PM)..." << luch_bas[1] << "\n";
  cout << "Fuerza (FUE) ..." << luch_bas[2] << "\n";
  cout << "Rapidez (RAP) ..." << luch_bas[3] << "\n";
  cout << "Precisión (PRE) ..." << luch_bas[4] << "\n";
  cout << "Sabiduría (SAB) ..." << luch_bas[5] << "\n";
  cout << "Espíritu (ESP) ..." << luch_bas[6] << "\n";
}
Jacek Cz
  • 1,872
  • 1
  • 15
  • 22