Hello I apologise if im posting in the wrong place at all im fairly new to your forums and i was wondering if someone could help me with this bit of code im writing. Its supposed to roll 4 random d6 dice and then minus the smallest roll and print the result at the end. It seemed all working but when i ran it it just outputs 0 at the end. I can't see why as im very new to c++ and am teaching myself here, but i went and checked if the randoms where working allright and they were so im stumped?
Can anyone please figure out what is wrong with my code and any suggestions you have would be great because im eager to learn any new tricks, its bloody hard teaching yourself when you have no one at all guiding you. Trial and error sucks.
Anyways heres my code:
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <stdio.h>
#include <time.h>
using namespace std;
void rolling();
void test_1();
void test_2();
void test_3();
void result();
int rolls[4];
int x;
int y;
int z;
int main()
{
srand((unsigned)time(0));
rolling();
return 0;
}
void rolling()
{
int roll_1 = rand() % 6 + 1;
int roll_2 = rand() % 6 + 1;
int roll_3 = rand() % 6 + 1;
int roll_4 = rand() % 6 + 1;
int rolls[] = { roll_1, roll_2, roll_3, roll_4 };
test_1();
return;
}
void test_1()
{
if (rolls [0] >= rolls [1]) {
x = rolls [1];
test_2();
}
else {x = rolls [0];
test_2();
}
return;
}
void test_2()
{
if (rolls [2] >= rolls [3]) {
y = rolls [3];
test_3();
}
else { y = rolls [2];
test_3();
}
return;
}
void test_3()
{
if (x >= y) {
z = y;
result();
}
else { z = x;
result();
}
return;
}
void result()
{
int r = (((rolls[0] + rolls[1]) + (rolls[2] + rolls[3])) - z);
cout << r << endl;
system ("PAUSE");
return;
}
Thank you very much everyone on Daniweb forums i appreciate your help and advice.