-
Help with c++ coding
We want to put in our arckives this information about the players , can we get help how to make a c++ code. We want it to be as what we wrote below. You can see our startings code in the end of articl but we couldnīt more.
1. Programet start with writing the name of the team
Write the name of the team: Kotoko
2. Menu it will shows with two options , add a new player or show all the players.
Teams namn: Kotoko
(1) Add new player.
(2) Show all the players.
(0) Close
Choose: 1
Teams namn: Kotoko
Add a player nr 1
First name: John // You write all this information
Last name: Phillip
Age: 24
Position: Forward
*When you put the player programet go to the menu
Teams namn: Kotoko
(1) Add new player.
(2) Show all the players.
(0) Close
Choose: 2 // to show all the players
Teams namn: Kotoko
1. Phillip, John 37 Forward
2. Ritchard, Jan 26 Back
3. Nils , Hans 32 Goalkeeper
Click en key to go to menu
Teams namn: Kotoko
(1) Add new player.
(2) Show all the players
(0) Close
Choose: 0
Code:
#include <iostream>
#include <iomanip>
using namespace std; //
int main () //
{
int tal1; //
int tal2; //
int tal3; //
cout << "\nTEAMPROGRAMMET" << endl; //
cout << "\nWrite the name of the team" << endl; //
cin >> tal2;
cout << '\n';
cout << "(1) Add a new player." << endl; //
cout << "(2) Show all the players." << endl;
cout << '\n';
cout << "Choose: \n\n";
int player;
cin >> player;
if (player == 1)
{
cout << "TEAMPROGRAMMET: kotoko" << endl;
cout << "Add in new player nr 1" << endl;
}
return 0; //
}
-
Well you want to store the players information. You have options here. My best advice would be create a structure for these players
Code:
struct Player{
string firstName;
string lastName;
string position;
int age;
};
and then you can create a vector of pointers to hold these structs.
vector <Player*> p;
Not sure how much you know about vectors, structures and pointers. Im pretty sure there is a tutorial on this at this website.
Im also sure there might be easier ways to do this, but tell us exactly what do you need help with? is it storing the players?
-
Hi
Thank you for your replying
Iam really need a program for our fotballs teams basket , fotball , vollyball .To start the code with writing the name of one team , exemple Fotball. When i wrote it will come up a menu list with two options:
The team is: Fotball
1) Add a new player
(2) Show all the players
if i choose (1) it will give me:
The team is : Fotball
Add in new player nr (1).
Here i have to write the player first name , last name , age and position (That you suggesed). When i finished this one it will go back automatic to the menu. i will choose this time nr (2) which it is going to show the list of the player , (i wrote three players) on my first post. When all the players seen , i want to click one key to go back to the menu again. If i choose 0 any time i will close the code. Hope you understand and want to help us. Thanks
-
You don't need all those empty comments:
Do you know how to use while loops?
-
Just make one big menu where you can pick football, basket ball, etc. Then you pick one and it opens a sport specific file and reads the info from it, this way you can close the program and not lose the data. Then adding a new player you write to the file, for all file operations you could use fstream.
-
Please iam not so good in programing , i have tried all you wrote but i couldnīt and i have spent mutch time to fix this code , i hope to get help from you. Thanks
-
What about go to the tut section of the site ??
-
If you dont know alot about programming this project might be alittle difficult to jump into. Try first reading some tutorials looking into case statements loops and as someone suggested file reading and writing to store your data externally. After you learn all that then you can put it together and make this program.
-
I agree with you abot what you wrote but in this case we are in the finishing of our archives and evrey thing have to be ready tomorow for to show that with other work to the committe of the team , otherwise i could wait until i learn me . Please do to me this time and i promise to do what you said.
-
God bless you , iam waiting your help
-
Here I wrote up a program that does what you want(or what I think you want), it stores, reads, and can remove players on different teams. It requires minimal change on your part, I even commented on the parts that need to be changed. The only change you need to make is to the name of the teams, I just put football,soccer,hockey,and basketball since those are sports teams. You can just change it to the name of the team, like kotoko, and it will work. Did you want it so you type the team's name and it retrieves the data or you can create a team if it doesn't exist?? Also, I know my code is a little messy and uncommented, it's because I was busy today and thought you needed it for tomorrow so I just made sure it was done by tonight. There may have been an easier way to do this but I did it the way I like to, with vectors. The code was written on Dev-C++ 4.9.9.2 compiler so it should compile on most compilers. Attached:
-
I really thanks you from my heard. I have only one question:
When the code start with Choose a sport , i want after this it come: Write your team:
And enstead of choosing nr 1 i want to write fotball .
The last you forgot to but 0 if i want to close the code any time .
-
So something more like this:
-
Evrything is perfect now , only instead of type exit to quit i want to write type 0 to quit.
*Ypu forgot to put (Position) with list of:
First name
Last name
Age
Position
I am really appricating you help. You are a good man. Thanks
-