I am ahving trouble getting the names in a text file to display on the console. The text file is setup like this:
Bob Julie Amy Bubba Thor
here is my code, any help will be greatly appreciated.
CODE
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int play_or_quit(int num);
const int SizeOfString = 7;
void CnameInputFile(string cname[SizeOfString]);
void CnameOutputFile(string cname[SizeOfString]);
void stars();
int main()
{
int num;
int pnum, cnum;
char pname[25];
bool gameover;
string cname[SizeOfString];
cnum = (rand() + time(0)) % 100;
gameover = false;
stars();
cout << "***********| Welcome to |***********" << endl;
cout << "***********| High |***********" << endl;
cout << "***********| Number |***********" << endl;
stars();
cout << endl;
cout << " Continue = 1 Quit = 2 \n";
cin >> num;
cout << endl;
if (num != 1)
return 1;
cout << endl;
cout << " Continue = 1 Quit = 2 \n";
cin >> num;
cout << endl;
if (num != 1)
return 1;
cout << "Player please enter your name:\n";
cin >> pname;
cout << endl;
CnameInputFile(cname);
CnameOutputFile(cname);
cin >> pname;
cout << " " << pname << " vs. The Computer" << endl;
cout << endl;
while (!gameover)
{
cout << pname << " pick a number between 1 and 100\n";
cin >> pnum;
cout <<endl;
cout << "The number you chose is " << pnum << endl;
cout << endl;
cout << "The computer is picking its number\n";
cout << cnum;
cout << endl;
if (pnum > cnum)
{
cout << pname << " is the winner" << endl;
gameover = true;
return 0;
}
else
if (pnum < cnum)
cout << "Computer is the winner " << endl;
cout << "Try again!" << endl;
cout << endl;
}
return 0;
}
void stars()
{
cout << "************************************" << endl;
cout << "************************************" << endl;
cout << "************************************" << endl;
}
void CnameInputFile(string cname[SizeOfString])
{
ifstream incnames;
incnames.open("ComNames.txt");
int i;
for(i = 0; i < SizeOfString - 1; i++)
{
incnames >> cname[i];
}
incnames.close();
}
void CnameOutputFile(string cname[SizeOfString])
{
int j = 0;
if(cname[j], j++)
cout << cname[j];
}