Trouble Converting Variables

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 8
Reputation: Mr.PinkBunny is an unknown quantity at this point 
Solved Threads: 0
Mr.PinkBunny's Avatar
Mr.PinkBunny Mr.PinkBunny is offline Offline
Newbie Poster

Trouble Converting Variables

 
0
  #1
Dec 22nd, 2004
I'm using a code segment out of a book that I'm learning from. For some reason it isn't working and I haven't been able to figure out how it works.

When I use the srand function it says I can't convert my (short) Number variable to a (void) srand (time(NULL)) there is an error
.

Errors:
- Error C2440: '=' : cannot convert from 'void' to 'short'
Expressions of type void cannot be converted to other types
-Warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data



#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

main ()
{
	short Number, Guess = 0;

             Number = srand (time(NULL));
             Number++;

	while (Guess != Number)
	{
		cout <<"Enter a number between 1 and 100: ";
		cin>> Guess;
	

	if (Guess < Number)
	  {
		cout <<"You are guessing to low." <<endl;
	  }

	if (Guess > Number)
	  {
		cout <<"You are guessing to high." <<endl;
	  }
    }


cout <<"You got it bud, the winning number is: " <<Number <<endl;

return 0;
}
:evil::cry::evil::cry::evil::cry::evil::cry::evil:
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: Trouble Converting Variables

 
0
  #2
Dec 22nd, 2004
srand() only establishes the seed for the rand() function.
Try
  1. srand (time (0));
  2. Number = rand ();
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC