Inputting batting average- expected unqualified id before << token???

Hi im new to programming and help would be greatly appreciated. Im recieving the error where it says string << "Enter Players name "; ???


// This program determines batting average
//
// Author: Christopher Valvo
//
// Date: 2/17/20

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
string name1; // enter batters name
int hits, atBats; // enter # of hits & at bats // enter times at bat
float average; // % of batters hits & at bats

string << "Enter the players name: " ;

getline(cin,name1);

cout << "Enter the number of at bats: " ;

cin >> atBats;

cout << "Enter the number of hits: " ;

cin >> hits;

// Calculate the batting average
cout << setprecision(3) << fixed;

average = static_cast<double>(hits) / atBats;


cout << name1 << ": " << "Has a batting average of: " << average << endl;

return 0;
}
You need to add #include <string> for getline

and string << "Enter the players name: ";

should be

std::cout << "Enter the players name: ";
Last edited on
Topic archived. No new replies allowed.