Anyone here know C++ or programming in general
I need help with this program. I made a structure, and an array out of that structure. When I try entering a name as a string, an infinite loop ensures. What is the problem?
#include <iostream>
#include <string>
const int size = 12;
struct soccer
{
std::string name;
float points, jersey;
};
void input(soccer []);
int main()
{
soccer info[size];
float total;
input(info);
}
void input(soccer info [])
{
for (int i = 0 ; i < size ; i++)
{
std::cout << "Enter the name of soccer player #" << i+1 << ": ";
std::cin >> info[i].name;
std::cout << "Enter the jersey number for this player:";
std::cin >> info[i].jersey;
while (info[i].jersey < 0)
{
std::cout << "The jersey number cannot be a negative number. Please enter a value number for jersey: ";
std::cin >> info[i].jersey;
}
std::cout << "Enter the number of points scored by this player: ";
std::cin >> info[i].points;
while (info[i].points < 0)
{
std::cout << "Points scored cannot be a negative number. Please enter a valid number for points: ";
std::cin >> info[i].points;
}
}
}
cout << ...simply doesn't appear on the screen because you don't flush buffers.cout.flush()orcout << std::endl;may help.