I am writing a program that is like a guessing die and card game. It simulates the user rolling a die, and based on what they toll a card is generated that is equivalent to the amount of points they received in that round based. For example, rolling 1 has a card that says the user caught a big fish, and earned 20 points. The problem that I have is incrementing points and keeping a running total. The program only displays the die number rolled, as opposed to how many points were earned that round. It also does not print the correct final total. I have been tinkering with it for a few days, which leads me to believe I am making a simple mistake. Please help. My code is pasted below.
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<string>
using namespace std;
class Dice {
private:
public:
int dicevalue;
int rollDice() {
srand(time(NULL));
int dicevalue = rand() % 6 + 1;
return dicevalue;
}
};
class Points {
public:
int total;
int dicevalue;
int Points::getpoints(int dicevalue) {
switch (dicevalue) {
case 1:
cout << "\nYou rolled " << dicevalue << " \n" << endl;
cout << "Huge Fish \n";
total = 0 + 20;
break;
case 2:
cout << "\nYou rolled " << dicevalue << " \n" << endl;
cout << "Old shoe \n";
total = 0 + 5;
break;
case 3:
cout << "\nYou rolled " << dicevalue << " \n" << endl;
cout << "Little Fish\n";
total = 0 + 10;
break;
case 4:
cout << "\nYou rolled " << dicevalue << "\n" << endl;
cout << "Small prawn\n";
total = 0 + 7;
break;
case 5:
cout << "\nYou rolled " << dicevalue << "\n" << endl;
cout << "Shark\n";
total = 0 + 40;
break;
case 6:
cout << "\nYou rolled " << dicevalue << "\n" << endl;
cout << "Huge Catfish\n";
total = 0 + 30;
break;
}
return total;
}
int getPoints() {
return dicevalue;
}
};
class Game : public Points {
private:
Dice dice;
Points points;
public:
int Game::playgame() {
int choice, points_to_add;
total = 0;
points_to_add = 0;
int dicevalue = dice.rollDice();
total = total;
points_to_add = total + points.getpoints(dicevalue);
cout << "The value of total is: " << total << endl;
//total = total + points_to_add;
cout << "You earned:" << total << " points this round" << endl;
//system("pause");
return total;
}
/*
int getPoints() {
return total;
}
*/
};
int main() {
int choice;
int mytotal = 0, total, points_to_add = 0;
Game game;
do {
cout << "Welcome to Go Fish 2.0!" << endl;
game.playgame();
cout << "Would you like to play again?" << endl;
cout << "1 to play, 0 to exit: " << endl;
cin >> choice;
} while (choice == 1);
mytotal = points_to_add + game.playgame();
cout << "My Total game points are" << mytotal << endl;
system("pause");
return 0;
}