I made a death clock and my random number generator always makes 41 so i dont know if i did something wrong or what someone please help
I made a death clock and my random number generator always makes 41 so i dont know if i did something wrong or what someone please help
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
string answer;
int main()
{
int number>=0 && number<=100);
oops it was
int number=rand();
but i always get 41
Use code tags!
You must seed the random number generator
IE
Code:#include <ctime> #include <cstdlib> #include <iostream> using namespace std; int main() { srand(time(NULL)); cout << rand()%50 << endl; cout << rand()%50; }
Im still new to this. ok now it doesnt reckonize my inout number so how do connect the random number generator to the number
exactly how you did it before
Seeding the generator is a one time thing, usually placed at the top of int mainCode:int number = rand();
ok thanks much
ok now numbers are appearing at the beginning of the program and my number still comes up 41
Code:#include <iostream> #include <cstring> #include <cstdlib> using namespace std; string answer; int main() { int number = rand(); srand(time(NULL)); cout << rand()%50 << endl; cout << rand()%50; // User Information Storage char firstname[15]; char middlename[15]; char lastname[15]; char fullname[45]; //Introduction to Deathclock cout<<"Razz-ma-tazz : Hello, I am Razz-ma-tazz.\n"; cout<<"Razz-ma-tazz : First off what is your first name, Darlin?\n"; cout<<"User : "; cin.getline ( firstname, 15 ); cout<<"Razz-ma-tazz : Ok "<< firstname <<", Now what is your last name?\n"; cout<< firstname <<" : "; cin.getline ( lastname, 15 ); cout<<"Razz-ma-tazz : Now, if I can just get your middle name.\n"; cout<< firstname <<" : "; cin.getline ( middlename, 15 ); cout<<"Razz-ma-tazz : "<< firstname <<" "<< middlename <<" "<< lastname <<" am I right?\n"; cout<< firstname <<" : "; cin>> answer; strcat ( fullname, firstname ); strcat ( fullname, " " ); strcat ( fullname, middlename ); strcat ( fullname, " " ); strcat ( fullname, lastname ); if (answer == "yes") { cout<<"Razz-ma-tazz : Ok baby, we're almost done.\n"; } else if (answer == "no") { cout<<"Razz-ma-tazz : Well, It don't madder now baby, it's what we usin.\n"; } cin.get(); cout<<"Razz-ma-tazz : Alright baby here we go!\n"; cout<<"Razz-ma-tazz : Kashmahammaflipflap!\n"; cout<<"Razz-ma-tazz : Your are going to die in "<< number <<" years.\n"; cout<<"Razz-ma-tazz : Wow, "<< number <<".\n"; if (number <= 24) { cout<<"Razz-ma-tazz : Ooh that's too bad, but aaa why don't you let me get the rest of that cash in there.\n"; } else if (number >= 25 && number <= 50) { cout<<"Razz-ma-tazz : You still have a while to live your dreams out hunny.\n"; } else if (number >= 51) { cout<<"Razz-ma-tazz : Congradulations baby, your going to live a long healthy life!\n"; cout<<"Razz-ma-tazz : Now, wither its happy or not I dont't dare say...\n"; } cout<<"Razz-ma-tazz : Well, there you go sweetheart. That'll be 35 dollars.\n"; cout<<"Razz-ma-tazz : Bubye now and may you live a wonderful life.\n"; cin.get(); }
check this
What compiler/IDE are you using?Code:#include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(NULL)); int number = rand(); // User Information Storage char firstname[15]; char middlename[15]; char lastname[15]; char fullname[45]; string answer; //Introduction to Deathclock cout<<"Razz-ma-tazz : Hello, I am Razz-ma-tazz.\n"; cout<<"Razz-ma-tazz : First off what is your first name, Darlin?\n"; cout<<"User : "; cin.getline ( firstname, 15 ); cout<<"Razz-ma-tazz : Ok "<< firstname <<", Now what is your last name?\n"; cout<< firstname <<" : "; cin.getline ( lastname, 15 ); cout<<"Razz-ma-tazz : Now, if I can just get your middle name.\n"; cout<< firstname <<" : "; cin.getline ( middlename, 15 ); cout<<"Razz-ma-tazz : "<< firstname <<" "<< middlename <<" "<< lastname <<" am I right?\n"; cout<< firstname <<" : "; cin>> answer; strcat ( fullname, firstname ); strcat ( fullname, " " ); strcat ( fullname, middlename ); strcat ( fullname, " " ); strcat ( fullname, lastname ); if (answer == "yes") { cout<<"Razz-ma-tazz : Ok baby, we're almost done.\n"; } else if (answer == "no") { cout<<"Razz-ma-tazz : Well, It don't madder now baby, it's what we usin.\n"; } cin.get(); cout<<"Razz-ma-tazz : Alright baby here we go!\n"; cout<<"Razz-ma-tazz : Kashmahammaflipflap!\n"; cout<<"Razz-ma-tazz : Your are going to die in "<< number <<" years.\n"; cout<<"Razz-ma-tazz : Wow, "<< number <<".\n"; if (number <= 24) { cout<<"Razz-ma-tazz : Ooh that's too bad, but aaa why don't you let me get the rest of that cash in there.\n"; } else if (number >= 25 && number <= 50) { cout<<"Razz-ma-tazz : You still have a while to live your dreams out hunny.\n"; } else if (number >= 51) { cout<<"Razz-ma-tazz : Congradulations baby, your going to live a long healthy life!\n"; cout<<"Razz-ma-tazz : Now, wither its happy or not I dont't dare say...\n"; } cout<<"Razz-ma-tazz : Well, there you go sweetheart. That'll be 35 dollars.\n"; cout<<"Razz-ma-tazz : Bubye now and may you live a wonderful life.\n"; cin.get(); }
-edit-
Note that I moved the string from being global (outside main) to be inside. Global variables should be avoided when having it global provides absolutely no benefits or could be easily made non-global
Ignore that if you don't understand
bloodshed Dev-c++
the one recommended for beginngers by this site
now how would i limit it under like 100 or so?
yeah i understood itNote that I moved the string from being global (outside main) to be inside. Global variables should be avoided when having it global provides absolutely no benefits or could be easily made non-global
Ignore that if you don't understand