Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions exercises/risk-risiko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,36 @@
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;

void throwDices(int *v, size_t n){
for (int i=0; i<n; i++){
v[i] = (rand() % 6) + 1;
}
sort(v, v+n, greater<int>());
}

int main() {
srand(time(nullptr));
int v1[3],v2[3];
char chs[3]= {'N', 'M', 'O'};
throwDices(v1, 3);
throwDices(v2, 3);
cout << "Red dices: " << endl;
for (int i=0; i<3; i++){
cout << v1[i] << " (" << chs[i] << ")"<< endl;
}
cout << "\nBlue dices: " << endl;
for (int i=0; i<3; i++){
cout << v2[i] << " (" << chs[i] << ")"<< endl;
}

printf("\n%3.c%5.c\n", 'R', 'B');
for (int i=0; i<3; i++){
cout << chs[i] << " " << v1[i] << " vs " << v2[i] << " => " << (v1[i]>v2[i] ? "red win" : "blue win" ) << endl;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manca return 0
inoltre, hai scritto tanto codice dentro il main, potresti spezzettarlo in più funzioni separate

}