Hjälp med tärningskast program! C++
Hej, en kompis till mig har gjort ett program här som jag tänkte använda mig av, men som nu är bortrest. Har kommit en bit och bytt ut ett par variabler. Men jag är ingen direkt haj på att programmera, så hjälp skulle vara till en stor tacksamhet!
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
void slumpgen (int tarning[], int tarningkvar);
int main ()
{
int s;
int S;
int tarningkvar;
int tarning;
int spelare;
int tarningar [6];
int liv [20];
int tempscore;
int nuscore;
char val;
system("mode 83,40");
bool fortsatt = true;
do
{
cout << " MENU \n";
cout << "1. Starta spelet \n";
cout << "2. Instruktioner \n";
cout << "3. Kredits\n";
cout << "4. Avsluta\nDitt val här: ";
cin >> val;
system("cls");
switch(val)
{
case '1': //Spelet
cout << "Välj antal spelare, max 20: ";
cin >> spelare;
for (int n=0; n<spelare; n++) //Antal spelare
{
liv [n]=30;
}
cout<< "Du har valt " <<spelare<< " antal spelare." <<endl;
system("pause");
system("cls");
cout<< "Poäng" <<endl;
cout<< "Spelare " << setw(6) << "Poäng \n" <<endl; //Ställer upp spelare och poäng
for (int x=0; x<spelare; x++)
{
cout<< "Spelare" << x+1 << setw(6)<< liv[x] <<endl;
}
cout<< "Tryck s för att starta";
cin>> s||S;
cout<< endl;
while (spelare>1)
{
for (int i=0; i<spelare; i++)
{
cout<< "Spelas nu: Spelare " << i+1 <<endl;
tarningkvar=6;
slumpgen (tarningar, tarningkvar);
for (int b=0; b<tarningkvar; b++)
{
switch (tarningar[b])
{
case 1:
cout<< "Tärning nummer: " << b <<endl;
cout<< "_______" << endl;
cout<< "| |" << endl;
cout<< "| O |" << endl;
cout<< "|_____|" << endl;
break;
case 2:
cout<< "Tärning nummer: " << b <<endl;
cout<< "_______" << endl;
cout<< "|O |" << endl;
cout<< "| |" << endl;
cout<< "|____O|" << endl;
break;
case 3:
cout<< "Tärning nummer: " << b <<endl;
cout<< "_______" << endl;
cout<< "|O |" << endl;
cout<< "| O |" << endl;
cout<< "|____O|" << endl;
break;
case 4:
cout<< "Tärning nummer: " << b <<endl;
cout<< "_______" << endl;
cout<< "|O O|" << endl;
cout<< "| |" << endl;
cout<< "|O___O|" << endl;
break;
case 5:
cout<< "Tärning nummer: " << b <<endl;
cout<< "_______" << endl;
cout<< "|O O|" << endl;
cout<< "| O |" << endl;
cout<< "|O___O|" << endl;
break;
case 6:
cout<< "Tärning nummer: " << b <<endl;
cout<< "_______" << endl;
cout<< "|O O|" << endl;
cout<< "|O O|" << endl;
cout<< "|O___O|" << endl;
break;
default:
cout<< "ERROR";
}
}
cout<< "Vilken/Vilka tärningar vill du spara?" << endl;
}
}
break;
case '2': //Instruktioner
cout<< "There are 6 dices in the game, every player starts with 30 points, \nlast to 0 wins." <<endl;
cout<< "The goal in this game is to gather 30 points each turn. \n";
cout<< "The player can save how many dices he wants, but he must save atleast 1 dice each \n\"throw\".";
cout<< "If the player gets 30 points after all of his throws, it's the next \nplayers turn.";
cout<< "If he doesn't achieve 30 points, he looses the difference between his points and 30.";
cout<< "\nIf he achieve more than 30 points, he gets extra throws.";
cout<< "These throws decrease the \npoints of the player who's turn was before him.";
cout<< "The player will have to get the \nnumber that exceeds 30.\n \n Example:\n If the player get 32 points,";
cout<< "he needs to get the number 2 in his next throws." ;
cout<< "If he doesn't get any 2's, the turn goes on to the next player." ;
cout<< "The points that he gather is withdrawn from the player before him.";
cout<< "\n \n When a player gets to 0 point he's out of the game, last to 0 wins.\n" <<endl <<endl <<endl <<endl;
system("pause");
system("cls");
break;
case '3': //Kredits
cout<< "xxxxxx xxxxxxxx\n";
system("pause");
system("cls");
break;
case '4':
fortsatt = false;
break;
default:
cout << "Felinmatning.\n\n";
}
}while (fortsatt);
return 0;
}
void slumpgen (int tarning[], int tarningkvar)
{
srand(time(0));
for (int a=0; a < tarningkvar; a++)
{
tarning [a] = rand()%6 +1 << ' ';
}
}
Vad jag vill ha är ett program där man kan slå ett valfritt antal kast med två tärningar och där programmet skriver ut resultatet. Alla kast ska vara slumptal såklart. Dessutom vill jag att antalet kast skall skrivas ut, totalsumman och antalet ettor(totala summan av alla kast i slutet av programmet). Kommentarer i programmet skulle också vara underbart så jag förstår vad som händer vid utskriften!
Exempel på hur jag vill att de ska se ut:
Hur många kast? 3
Tärning 1 kast nr 1: 4
Tärning 2 kast nr 1: 3
Summan är 7
Tärning 1 kast nr 2: 3
Tärning 2 kast nr 2: 6
Summan är 9
Tärning 1 kast nr 3: 2
Tärning 2 kast nr 3: 1
Summan är 3
Totalsumman är 19
Du har fått 1 etta
Du har fått 1 tvåa
Du har fått 2 treor
Du har fått 1 fyra
Du har fått 0 femmor
Du har fått 1 sexa
Vore tacksam i evigheter ifall någon kunde ge sig på detta och hjälpa mig!