|
-
January 1st, 2012, 12:06 PM
#1
Srand function problem and a different problem
#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
#include <ctime>
#include <iomanip> //In this line, compiler gives warning C4067: unexpected tokens following //preprocessor directive - expected a newline but program still executes instead of this. //What is the reason of this error? How can I fix it?
using std::setw;
using namespace std;
Another question,
I have the following code in my constructor:
srand(int(time(NULL)));
for(int i=0; i<(99-1); i++){ //shuffling card;
int r = i + (rand() % (99-i)); // Random remaining position.
int temp = kartSayilar;
kartSayilar = kartSayilar[r];
kartSayilar[r] = temp;
}
The aim of this is to shuffle numbers in the kartSayilar array randomly. I creates two objects of this in a different .cpp file but when program executes, both objects have the same random numbers. I think my srand function doesn't work. How can i fix it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|