Skip to content

Instantly share code, notes, and snippets.

@roshanlam
Created October 14, 2020 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roshanlam/2d48875c923481b348768485b0b94647 to your computer and use it in GitHub Desktop.
Save roshanlam/2d48875c923481b348768485b0b94647 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(){
srand(time(0));
const int MAX = 100;
int totals = 0;
int randoms[MAX];
int counts[6] = {0};
string values[6] = {"ones","twos","threes", "fours","fives","sixes"};
ifstream inFile;
inFile.open("random3.txt");
if(inFile)
for(int i = 0; i < MAX; i++)
inFile>>randoms[i];
else{
cout<<"file not found, creating randoms"<<endl;
for(int i = 0; i < MAX; i++)
randoms[i] = 1+rand()%6;
}
inFile.close();
for(int number : randoms){
++counts[number-1];
}
for(int i = 0; i < 6; i++){
cout<<"\n"<<values[i]<<"\t"<<counts[i];
totals+=counts[i];
}
cout<<"\ntotals\t"<<totals<<endl;
ofstream outFile;
outFile.open("random2.txt");
for(int num : randoms)
outFile<<num<<endl;
outFile.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment