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<cstdlib>
class Dice{
private:
int dicevalue;
public:
int rollDice(){
int ran = rand() %6 +1;
dicevalue = ran;
return dicevalue;
}
};
class Points{
public:
int getpoints(int dicevalue){
switch(dicevalue){
case 1:
printf("\nYou won %d points\n",dicevalue);
return 1;
break;
case 2:
printf("\nYou won %d points\n",dicevalue);
return 2;
break;
case 3:
printf("\nYou won %d points\n",dicevalue);
return 3;
break;
case 4:
printf("\nYou won %d points\n",dicevalue);
return 4;
break;
case 5:
printf("\nYou won %d points\n",dicevalue);
return 5;
break;
case 6:
printf("\nYou won %d points\n",dicevalue);
return 6;
break;
}
return -1;
}
};
class Game{
private:
int total=0;
Points points;
Dice dice;
public:
int playgame(){
int con;
do{
int dicevalue = dice.rollDice();
int points_to_add=points.getpoints(dicevalue);
total = total + points_to_add;
printf("\nif you want one more term press 1 or 0 : ");
scanf("%d",&con);
}while(con==1);
return total;
}
};
int main(){
Game game;
printf("\ntotal points are %d",game.playgame());
return 0;
}