Skip to content
Open
Changes from all commits
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
43 changes: 43 additions & 0 deletions exercises/risk-risiko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,46 @@
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
const char chs[3]= {'N', 'M', 'O'};
using namespace std;

void throwDices(int *v, int n);
void printThrows (int *v, int n);
void fight(int *v1, int *v2 , int n);

int main() {
srand(time(nullptr));
int v1[3],v2[3];
throwDices(v1, 3);
throwDices(v2, 3);
cout << "Red dices: " << endl;
printThrows(v1, 3);
cout << "\nBlue dices: " << endl;
printThrows(v2, 3);

fight(v1, v2, 3);
return EXIT_SUCCESS;
}

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

void fight(int *v1, int *v2 ,int n){
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

}