Hi working on this lab, and theres mistakes were i know im not writing the code correctly but i am trying, really am. If anyone couuld help me out with these errors, or notice were i am writing incorrectly can you post correct way. thank you..
Description:
Create a program that will display baseball players names(just last names) and averages. The most players you would have to process is 10. Input the players last name, at-bats, and hits. A players’ average is calculated by dividing the players’ hits by the number of at-bats. Averages are generally displayed to 3 decimal points. For any player, if the number of hits exceeds the number of at-bats, display an error message.
Your program should have 2 arrays. One to store the names, and another one to store the averages. You will need to include the string library in order to have string variables.
Errors:
11 `string' does not name a type
21 conflicting declaration 'char Name'
13 'Name' has a previous declaration as `std::string Name'
21 declaration of `char Name'
13 conflicts with previous declaration `std::string Name'
25 initializer fails to determine size of `Array_names'
25 invalid initializer
26 initializer fails to determine size of `Array_avg'
26 invalid initializer
33 no match for 'operator<<' in 'std::cin << Name'
35 no match for 'operator!=' in 'Name != QUIT'
38 \p no match for 'operator[]' in 'Array_names[Name]'
38 expected primary-expression before "format_name"
38 expected `;' before "format_name"
42 name lookup of `count' changed for new ISO `for' scoping
29 using obsolete binding at `count'
99 cannot convert `std::string' to `int' in return
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
int main()
{
void string format_name(char Name);
string Name;
//local constants
int Average = 0;
int MAX = 10;
int At_Bat = 0;
int Hit = 0;
char QUIT = 'Q';
char Name;
//local variables
char Array_names[]=Name;
int Array_avg[]=Average;
/***********************************************************/
for (int count = 0; count <= 10 ; count ++)
{
cout <<"\n\n\n\n";
cout <<"Please enter player name, or Q to quit";
cin << Name;
while (Name != QUIT)
{
//call function to put name in array
Array_names[Name] = string format_name;
}
}
/*****************************************************************/
for (int i = 0; i <= count ; i++)
{
cout << "\n\n\n\n";
cout <<"Please Enter At bats";
cin >> At_Bat;
cout <<"Please Enter total hita";
cin >> Hit;
while (At_Bat >= Hit);
Array_avg[Average] = Hit/At_Bat;
}
/**********************************************************************
*Program Name :
*Author :
*Date :
*Course/Section : CSC 110
*Program Description: This function is designed to format a string
* to be 12 characters long. If the string is longer than 12 chars
* then the string will be truncated. If the string is shorter than
* 12 characters then it will be padded with spaces at the end.
*
*BEGIN - Format Name (input string)
* Init pad variable to # of chars the name is too long or too short
* IF (input string is too short)
* Pad the string with spaces
* ELSE //input string is too long
* Truncate the unwanted characters
* END IF
* Return the new formatted string
*END - Format Name
*********************************************************************/
{
string format_name(string Name);
//local constants
const int WIDTH = 12;
//local variables
int Pad = WIDTH - Name.length(); //# of chars too long or too short
/***********begin function body*****************************/
//if the name is shorter than the desired width
if (Pad > 0)
//pad the name with spaces so the length is correct
for (int Count = 0; Count < Pad; Count++)
Name = Name + " ";
else //the name is longer than the desired width
//truncate all characters after the desired width
Name = Name.substr(0, WIDTH);
//return the new string
return Name;
}//end format name
}