Adding a high score to a game

I am working on a dice rolling game, is there any way I can implant a high score into this code?

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
while(1==1){
srand(time(0));
int dice1,dice2,dice3,ddice1,ddice2,ddice3,dddice1,dddice2,dddice3;
for(int y=0;y<3;y++){
if(y==0)dice1=rand()%6+1;
if(y==1)dice2=rand()%6+1;
if(y==2)dice3=rand()%6+1;
}
for(int y=0;y<3;y++){
if(y==0)ddice1=rand()%6+1;
if(y==1)ddice2=rand()%6+1;
if(y==2)ddice3=rand()%6+1;
}
for(int y=0;y<3;y++){
if(y==0)dddice1=rand()%6+1;
if(y==1)dddice2=rand()%6+1;
if(y==2)dddice3=rand()%6+1;
}
cout<<"This is a game of rolling 3 dice and adding their values together.\nHit any key to roll the dice.....\n";
cin.ignore();
cout<<"\t die1\tdie2\tdie3\ttotal"<<endl;
cout<<"roll1:\t"<<dice1<<"\t"<<dice2<<"\t"<<dice3<<"\t"<<dice1+dice2+dice3<<endl;
cout<<"roll2:\t"<<ddice1<<"\t"<<ddice2<<"\t"<<ddice3<<"\t"<<ddice1+ddice2+ddice3<<endl;
cout<<"roll3:\t"<<dddice1<<"\t"<<dddice2<<"\t"<<dddice3<<"\t"<<dddice1+dddice2+dddice3<<endl<<endl;
cout<<"Your final score is\t"<<dice1+dice2+dice3+ddice1+ddice2+ddice3+dddice1+dddice2+dddice3<<endl;
cout<<"Play again? (1=yes)"<<endl;
int w;
cin>>w;
if(w!=1)break;
;}
return 0;
}
Last edited on
Do you mean that you want to remember what the highest total was in every run of the program?

If you want that, you'll have to store that information somewhere. Like in a file on a hard drive.
Yes I do. I want it to display the high score after it displays the score for every run. If it gets a higher number I then want that to be set as the new high score and so on.
Last edited on
http://www.cplusplus.com/doc/tutorial/files/

Put the high score in a file. Read the file each time you run the program.
Last edited on
Topic archived. No new replies allowed.