-
-
Save roshanlam/2d48875c923481b348768485b0b94647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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