Background
Creating a dice game where the dice roll value should be stored in a Linked List.
Question
How should an implementation of Linked List be completed in C++? '
Example (What I have tried using struct instead of class)
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
struct Score {
int d1;
int d2;
int total;
int totals[13];
int value;
struct Score * next;
}
score_dice1, score_dice2, score_total, score_totals;
struct Score * ordered_insert(struct Score * , struct Score * );
int dice = 2;
void Randomize() {
srand((unsigned) time(NULL));
}
int Random(int Max) {
return (rand() % Max) + 1;
}
int main(int argc, char * argv[]) {
struct Score * myList = NULL;
if (argc == 2) {
int dice_rolls;
dice_rolls = atoi(argv[1]);
Randomize();
for (dice = 2; dice <= 12; dice++)
score_totals.totals[dice] = 0;
for (dice = 0; dice < dice_rolls; dice++) {
score_dice1.d1 = Random(6);
score_dice2.d2 = Random(6);
score_total.total = score_dice1.d1 + score_dice2.d2;
score_totals.totals[score_total.total]++;
}
for (dice = 1; dice <= 13; dice++) {
printf("%i %i\n\r", dice, score_totals.totals[dice]);
}
} else {
std::cout << "How many times should we roll the dice?" << '\n' <<
"One number please" << '\n';
}
return 0;
}