ok it almosts works, the program stops when i enter the first at_BAT AND then hits and wont loop to get the neext persons at bat and hits.
error:
36 no matching function for call to `toupper(std::string&)'
ok here is ther part that isnt working...
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;
}
}
and this is whole code....
#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
using namespace std;
//function prototype goes outside main
string format_name(string Name);
int main()
{
string Name = "";
//local constants
int Average = 0;
int At_Bat = 0;
int Hit = 0;
const int MAX = 100;
string QUIT = "Q";
//local variables
string Array_names[MAX] = {""};
int Array_avg[MAX] = {0};
/*****************************************************************/
int count = 0;
for (count = 0; count <= 10 ; count ++)
{
cout <<"\n\n\n\n\n";
cout << setw(60) << "Please enter player name, or Q to quit";
cout << "\n";
QUIT = toupper (QUIT);
cin >> Name;
if(Name == QUIT)
break; //exit the loop
else{
//call function to put name in array
Array_names[count] = format_name(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