I need help putting function calling, function definition and function prototypes into this code #include #include #include using namespace std; int main() { int players; int score; string name; ofstream outFile; outFile.open("golf.txt", ios::app); cout << "Enter the number of golfers competing: "; cin >> players; for(int i = 0; i < players; ++i) { cout << "Enter the name of the competitor " << (i+1) << ": "; cin >> name; cout << "Enter their score: " ; cin >> score; cout << "Golfer: " << name << " Score: " << score << endl; outFile <<"Golfer: " << name << " Score: " << score << endl; if (outFile.fail()) { cout << "Error creating file. " << endl; exit (1); } } outFile.close (); cout << "File is created"; return 0; }
I need help putting function calling, function definition and function prototypes into this code
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int players;
int score;
string name;
ofstream outFile;
outFile.open("golf.txt", ios::app);
cout << "Enter the number of golfers competing: ";
cin >> players;
for(int i = 0; i < players; ++i)
{
cout << "Enter the name of the competitor " << (i+1) << ": ";
cin >> name;
cout << "Enter their score: " ;
cin >> score;
cout << "Golfer: " << name << " Score: " << score << endl;
outFile <<"Golfer: " << name << " Score: " << score << endl;
if (outFile.fail())
{
cout << "Error creating file. " << endl;
exit (1);
}
}
outFile.close ();
cout << "File is created";
return 0;
}
Step by step
Solved in 3 steps with 2 images