Question:
Repl link:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
using namespace std;
int main(){
// Variable initialization
int teamA_points = 0;
int teamB_points = 0;
bool is_running = true; // Determines if the program is running, set to false terminates the while loop which the game persists in.
char team_turn ;// The letter in this variable will be used to determine which team's turn it is
int draw_card ; // Pick a card from the deck. This picks a index from the array deck.
string deck[3]; // Used to represent the deck of cards, It is an array which contain strings and these strings represent the cards.
string answers[3];
string word ; // Used to split the options and the answer on the card into an array. The anwser is always the last index in the array
string user_answer;
string text ; // Is a tempoary variable used to split the text from cards.txt into the array named cards
int counter = 0; // Is an index for the cards array
ifstream file_cards("cards.txt"); // Opens the file cards.txt
ifstream file_answers("answers.txt"); // Opens the file answers.txt
int random_number; // Generates a random number of 1 or 0 which will be used to determine which team starts the game.
int points; // The number of points the team will be given if they get the answer correct.
int win_condition = 20 ; // The amount of points needed to win the game.
srand((unsigned) time(NULL)); // Generates a seed based of time for random numbers
// Splits the text from cards.txt into lines, These represent the cards and the options
while (getline(file_cards, text, '\n')){
deck[counter] = text;
counter += 1;
}
counter = 0 ; // Resets the counter to 0 for it to be used again
//Splits the text from answers.txt into lines, These represent the answers
while (getline(file_answers, text, '\n')){
answers[counter] = text;
counter += 1;
}
counter = 0; //Resests the counter to 0 for it to be used again
random_number = rand() % 2;
if (random_number == 0){ // Randomly selects which team starts the game
team_turn = 'A';
} else{
team_turn = 'B';
}
while (is_running){
cout << "It is team " << team_turn << "'s turn. Please pass the device over to that team" << endl;
draw_card = rand() % 3; // draws a random card between 0 and 3
cout << deck[draw_card] << endl; //Prints out the options on the drawn card
cout << "Choose the odd one out" << endl;
cin >> user_answer; // Sets a user input that should be between 1 and 4. If the answer is equal to the last index in the options array then the team gets two points
if(user_answer == answers[draw_card]){ // Checks if the answer is correct
cout << "Correct" << endl <<
"_________________________________________" << endl;
points = 2;
} else { // Gives the other team a chance to answer the question
cout << "Incorrect, pass the device to the other team." << endl << "Choose the Odd one out" << endl;
cin >> user_answer; //Checks the answer from the opposing team
if(user_answer == answers[draw_card]){ // Checks if the answer is correct
cout << "Correct" << endl <<
"_________________________________________" << endl;
points = 1;
} else{
cout << "Incorrect, The answer was " << answers[draw_card] << ". The next card will be drawn" << endl << "_________________________________________" << endl; // Prints out the correct answer
}
}
if (team_turn == 'A'){ // Gives out the points for the round whilst switching the team turn
teamA_points += points;
team_turn = 'B';
} else {
teamB_points += points;
team_turn = 'A';
}
system("CLS"); //This works on code blocks its just being a bitch on replit. I have commented it out because it is not working.
if (teamA_points >= win_condition){ // Checks if team A has won the game
cout << "Team A wins" << endl;
is_running = false;
} else if (teamB_points >= win_condition){ // Checks if team B has won the game
cout << "Team B wins" << endl;
is_running = false;
}
}
return 0;
}
My command line is giving an error on line 100. That specfic line has
system("CLS");
It works on code blocks just fine but give me this error in replit :
ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
Thanks in advanced.