So I'm working on this lab, and I'm trying to get the user to input the name of a game, and I want it to look like:
Input name of game x:
where x is the place in an array called games.
When I try to use
cout << "Input name of game " << games[i] << ": ";
there is an error in the less than symbols before games[i] and I cannot figure out why.
Main file:
#include <iostream>
#include <iomanip>
#include <string>
#include "game.h"
using namespace std;
int main()
{
int numGames;
int randomNumber;
string name;
string genre;
cout << "How many games have you played in the last year?\n";
cin >> numGames;
game* games = new game[numGames];
srand(100);
for (int i = 0; i < numGames; i++)
{
cout << "What is the name of the game?\n";
cin >> name;
cout << "What is the genre of " << name << "?\n";
cin >> genre;
cout << "Input name of game " << games[i] << ": ";
game* ptrObj = new game();
ptrObj->setName(name);
ptrObj->setGenre(genre);
randomNumber = rand() % 10 + 1;
ptrObj->setDifficulty(randomNumber);
games[i] = *ptrObj;
}
}
game.h:
#pragma once
#include <iostream>
#include <string>
class game
{
public:
game();
~game();
void setName(std::string);
std::string getName();
void setGenre(std::string);
std::string getGenre();
void setDifficulty(int);
int getDifficulty();
private:
std::string name;
std::string genre;
int difficulty;
};
gameImp:
#include "game.h"
#include <iostream>
#include <string>
game::game()
{
std::cout << "Creating a new game\n";
}
game::~game()
{
std::cout << "In the game destructor\n";
}
void game::setName(std::string n)
{
this->name = n;
}
std::string game::getName()
{
return this->name;
}
void game::setGenre(std::string g)
{
this->genre = g;
}
std::string game::getGenre()
{
return this->genre;
}
void game::setDifficulty(int d)
{
this->difficulty = d;
}
int game::getDifficulty()
{
return this->difficulty;
}