mardi 27 janvier 2015

C++ Random Function making smiley faces

I am working on a battleship c++ program. I am testing out how I want to go about setting the ships and the water. I have an array and I create a random number for each int inside the array using a for loop. The random number it generates is a smiley face.



#include <iostream>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[]) {
int picks = 0;
char arena[25] = {};
for(int i = 0; i != 24; i++) {
srand(time(0));
picks = rand() % 3;
arena[i] = picks;
}
for(int i = 0; i != 24; i++)
cout << arena[i];
cout << endl;
for(int i = 0; i != 24; i++) {
if(arena[i] = 1)
cout << "~";
else if(arena[i] = 2)
cout << "~";
else if(arena[i] = 3)
cout << "#";
}
cout << endl;

system("PAUSE");
}




Aucun commentaire:

Enregistrer un commentaire