HopefulCoder
11-13-2011, 11:09 PM
This is going to be a fairly simple question, but why does this always spit out 0?
#include <iostream>
#include <time.h>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
int roll;
int dice(){
srand(time(NULL));
int roll=rand()%2+1;
return roll;
}
int main(void){
char answer;
cout<<"Flip coin? (y or n) ";
cin>> answer;
if(answer=='y'||answer=='Y'){
dice();
cout<<roll;
}
else{
cout<<"You suck!";
}
}
#include <iostream>
#include <time.h>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
int roll;
int dice(){
srand(time(NULL));
int roll=rand()%2+1;
return roll;
}
int main(void){
char answer;
cout<<"Flip coin? (y or n) ";
cin>> answer;
if(answer=='y'||answer=='Y'){
dice();
cout<<roll;
}
else{
cout<<"You suck!";
}
}