Hi Guys can you help me with this problem ? I can't quite get it :(
I'm new in C++ :(
Write a C++ program to keep records and compute for the scores of 5 players. The information of each player contains: Nickname, Age and two best played scores.
The program will prompt the user to choose the operation of records from a menu as shown below:
==============================================
MENU
==============================================
1. Add record
2. View players records
3. Compute for the average
4. Show the player(s) who gets the max average.
5. Show the player(s) who gets the min average.
6. Exit
int main() {
char option;
cout << "=================================================\n";
cout << "\t\t\tMENU\n";
cout << "1. Add record\n";
cout << "2. View players records\n"
<< "3. Compute for the average\n"
<< "4. Show the player(s) who gets the max average.\n"
<< "5. Show the player(s) who gets the min average.\n"
<< "6. Exit\n";
switch (option)
{
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
}
system("pause>0");
return 0;
}
void addrecord(Plrrecord)
{
for( int i=0;i<5;i++)
{
cout<<"Enter your nickname:";
cin>>nickname;
cout<<"Enter age:";
cin>>age;
cout<<"Enter your 1st score:";
cin>>score1;
cout<<"Enter your 2nd score:";
cin>>score2;
}
}
void viewrecord(Plrrecord)
{
}
void average(Plrrecord)
{
#include<iostream>
usingnamespace std;
struct Plrrecord {
char nickname[100];
char age[100];
char average[100];
char score1[100];
char score2[100];
}plr;
void addrecord(Plrrecord);
void viewrecord(Plrrecord);
void average(Plrrecord);
void maxave(Plrrecord);
void minave(Plrrecord);
int main() {
char option;
cout << "=================================================\n";
cout << "\t\t\tMENU\n";
cout << "1. Add record\n";
cout << "2. View players records\n"
<< "3. Compute for the average\n"
<< "4. Show the player(s) who gets the max average.\n"
<< "5. Show the player(s) who gets the min average.\n"
<< "6. Exit\n";
switch (option)
{
case'1':
case'2':
case'3':
case'4':
case'5':
case'6':
break;//there should be a break statement after switch (unless its c#)
}
system("pause>0");
return 0;
}
void addrecord(Plrrecord Plr)//you also need data variable in function
{
for( int i=0;i<5;i++)
{
cout<<"Enter your nickname:";
cin>>Plr.nickname;//since the function is not inside the struct the name needs to be defined
cout<<"Enter age:";
cin>>Plr.age;//same as above
cout<<"Enter your 1st score:";
cin>>Plr.score1;//same as above
cout<<"Enter your 2nd score:";
cin>>Plr.score2;//same as above
}
}
void viewrecord(Plrrecord)
{
}
void average(Plrrecord)
{
}
That's not how you call a function. You clearly know how to call a function, because you do it successfully elsewhere in your code, but if you're still confused about how to do it, I strongly recommend going back to your textbook and making sure you understand it. It's absolutely crucial to C and C++ programming.
addrecord is done by the ctor, viewrecord by the overloaded << operator, average is calculated as objects are constructed.
Data types changes as per shadder & TheIdeasMan's suggestions, the latter also mentioning std::vector. Incorporating all
these good stuff, see below and shout if anything's unclear: