Help with the task

Hello, i'm very new to the programming, so as of now, i'm really terrible at it :D
I am trying to learn C++ while doing different tasks and this is one task which made me struggle a lot:

"There are x players in a team. Create a program that shows, how many players are taller than 175cm. The height of all the players are typed in via keyboard".

I am not even sure where shall i start, though i was able to successfully solve a good deal of other tasks. Any type of help would be appreciated!
How you would do this if I was telling you numbers, and when I'd finished you had to tell me how many of those numbers were bigger than 175?

Now program that.
Your last sentence is exactly, what i am not able to do.. Like i said, i'm pretty much terrible at this thing.
Shall i use if, else?
http://www.cplusplus.com/doc/tutorial/control/

this page is very handy in my opinion. Im not sure if you are familiar with different loops but if not, this page explains them well.
So do i have to use the loops here? If yes, i still do not know how.
I really need this, so if anyone could write me the code, it would be really appreciated!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
#include <deque>

	struct player
	{
		float height;
		float weight;
	};

void main()
{
int nrPlayers;
cout<<"Nr. of players =";
cin>>nrPlayers;
deque<player> players;

players.resize(nrPlayers);

for (int i=0; i< nrPlayers; i++)
{
	cout<<"insert player"<<i<<" height";
	cin>> players[i].height;
}


cout<<endl<<endl<<"players taller than 175 cm:"<<endl;
for (int i=0; i< nrPlayers; i++)
{

	if( players[i].height >175)
		cout<<"player"<<i<<"="<< players[i].height<<" accepted"<<endl;
}
system("pause");
}
Thank you! Appreciate it!
this is another way, which might be consider way easier(space it if u want it):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int x;
int z=0;
int *p;
int players;
cout<< "How many players are there on the team? ";
cin>> players;
p = new (nothrow) int [players];
for (x = 0; x<= players-1; x++){
printf("Heigh in centimeters for player %d: ", x+1);
cin>> p[x];
    }
for (x = 0; x<=players;x++){
if (p[x] > 175){
z+=1;
}
}
cout<<z-1<< " players are taller than 175 centimeters.";
return 0;
}
Last edited on
Topic archived. No new replies allowed.