• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ problem

Tibiamakers

yourolist.com
Joined
May 24, 2010
Messages
1,377
Best answers
0
Reaction score
90
Location
España
I have got an array called espanol, I want to add in position [0] a 0.2 if in the cin the user writes 0 and 0 if writes 1, but don't know how to make reference between argument and the inputs, because this function have to be general for 30 different


Code:
float espanol[5];
float 29 variables more like @up;
bool resultado;

int estadio(float [])
	{
		cout << "Juega en casa el " << "whatever" << "?" << endl;
		cin >> resultado;

		if (resultado == true){
			 [0] = {0.2};
		}else{
			 [0] = {0};
		}	

	return 0;
	}

int main ()
{
	

	estadio(español);
	
		system("pause");
		return 0;

}
don't know if I explained it well.. thanks
 

Znote

<?php echo $title; ?>
Staff member
Global Moderator
Premium User
Joined
Feb 14, 2008
Messages
6,747
Best answers
221
Reaction score
1,446
Location
Norway, Oslo
I did not understand that fully. D: Please explain better in English. D:
Also if you have compiling errors, show them.


Here is my assumption of what may be correct:
[cpp]float player[5];

void estadio(float player[])
{
int isEspanol;
cout << "Are you espanol?" << endl << " 0 = NO " << endl << "1 = YES" << endl;
cin >> isEspanol;

if (isEspanol == 1){
player[0] = {0.2};
}else{
player[0] = {0};
}
}

int main ()
{


estadio(player);

system("pause");
return 0;

}[/cpp]
 
OP
Tibiamakers

Tibiamakers

yourolist.com
Joined
May 24, 2010
Messages
1,377
Best answers
0
Reaction score
90
Location
España
haha isn't related with players:


this is the code for one case:
PHP:
void stadium(float [])
	{
		cout << "Plays in his stadium the team" << "not important" << "?" << endl;
		cin >> result;

				if (result == true){
			 team1[0] = {2};
		}else{
			 team1[0] = {0};
		}	

	}

int main ()
{
	
	stadium(team1);
	cout << team1[0];
		system("pause");
		return 0;

}
but I want this function can make this with 30 more variables so i want:

PHP:
void stadium (float [])
	{
		cout << "Plays in his stadium the team" << "NAME OF THE ARGUMENT 1 ( array that is in the argument )" << "?" << endl;
		cin >> result;

				if (result == true){
			 teamWrittedInTheArgument[0] = {2};
		}else{
			 teamWrittedInTheArgument[0] = {0};
		}	

	}

int main ()
{
	
	stadium(teamX);
		system("pause");
		return 0;

}
better explained now?


updated:

(explained with only txt):

I want a function that ask the user if the team of the argument plays in his stadium, he write 1 or 0 and depends of his response store in position 0 of the array that is in the argument
 
Last edited:

Baxnie

Active Member
Joined
Oct 5, 2007
Messages
89
Best answers
0
Reaction score
37
Location
Brazil
Code:
#include <iostream>
#include <vector>
#include <string>

class Team {
public:
 Team(const std::string& name) {
  m_name = name;
 }
 void askStadium() {
  std::cout << "Does team " << m_name << " plays in his stadium?" << std::endl;
  int answer;
  cin >> answer;
  if(answer == 0)
   m_data[0] = 0.2;
  else
   m_data[0] = 0;
 }
private:
 std::string m_name;
 float m_data[5];
};

int main()
{
 std::vector<Team> teams;
 teams.push_back(Team("Vasco"));
 teams.push_back(Team("Flamengo"));
 teams.push_back(Team("Corinthias"));
 
 for(unsigned int i = 0; i < teams.size(); ++i) {
  teams[i].askStadium();
 }
 return 0;
}
And here's the codepad:
http://codepad.org/HM3LAILG
 
Top