Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New branch verify #305

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
83 changes: 83 additions & 0 deletions exercises/risk-risiko.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,86 @@
M 3 vs 3 => blue win
O 2 vs 1 => red win
*/
#include <iotream>
#include <algorithm>
#include <cstdlib>d
#include <ctime>

using namespace std;



void compare()
{
int dim=3;
int attack_dice[dim];
int defend_dice[dim];
srand(static_cast<unsigned int>(time(nullptr)));

cout<<"Dadi di attacco:"<<endl;

for(int i=0;i<dim;i++)
{
attack_dice[i] = rand() % 6+1; // Genera numeri casuali tra 1 e 6.
cout <<attack_dice[i]<< endl;

}

cout<<"Dadi di difesa:"<<endl;

for(int i=0;i<dim;i++)
{
defend_dice[i]=rand()%6+1;
cout<< defend_dice[i]<<endl;
}

sort(attack_dice, attack_dice + dim, greater<int>());
sort(defend_dice, defend_dice + dim, greater<int>());
cout<<endl;
for(int i=0;i<dim;i++){
if(attack_dice[i]<=defend_dice[i])
{
cout<<attack_dice[i]<<"vs"<<defend_dice[i]<<" Win Blue
cout<<endl;
}
else
{
cout<<attack_dice[i]<<"vs"<<defend_dice[i]<<" Win Red
cout<<endl;

}

}

}

void gioca_ancora()
{
bool gioca_ancora=true;
int x;

while(gioca_ancora==true)
{
cout<<"Vuoi giocare ancora? (se si premi 1 se no premi 0)"<<endl;
cin>>x;
if(x==1)
{
compare();
}
else if(x==0)
{
gioca_ancora=false;
cout<<"Esci!"<<endl;

}
}

}

int main()
{
compare();
gioca_ancora();

return 0;
}
42 changes: 42 additions & 0 deletions exercises/verify2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
using namespace std;


void verify()
{
int x;

int count=0;
int N[10] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0};

cout<<"Inserisci il numero da verificare all'interno dell'array: ";
cin>>x;
cout<<endl;

for(int i=0;i<10;i++)
{
if(x==N[i])
{

count++;

}


}

cout<<"Il valore "<<x<<" è presente "<<count<<" volte nell'array "<<endl;

}

int main()
{
// placeholder
//int N[10] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0};

verify();



return 0;
}
Loading