Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 9th, 2007, 11:20 PM   #11
C.B.
Newbie
 
Join Date: Apr 2007
Posts: 9
Rep Power: 0 C.B. is on a distinguished road
It compiled, and this seems to be the kind of program I am trying to create. How do I get it to stop asking for a number so It begin the random selection? It says to Enter a Number or 0 to exit. But when I enter a number as 0 it just saves it on the list.
C.B. is offline   Reply With Quote
Old Jul 9th, 2007, 11:47 PM   #12
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 377
Rep Power: 0 King is an unknown quantity at this point
In the GetNumbers function change the if statement to:
if ( num == 0 )
     break;
The code before only had a single '=' where a double '=' was needed (Ben probably didn't even compile it so was an easy thing to miss). That will fix the error. From here you should add some error handling for practice.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Jul 10th, 2007, 2:50 AM   #13
C.B.
Newbie
 
Join Date: Apr 2007
Posts: 9
Rep Power: 0 C.B. is on a distinguished road
Quote:
Originally Posted by King View Post
In the GetNumbers function change the if statement to:
if ( num == 0 )
     break;
The code before only had a single '=' where a double '=' was needed (Ben probably didn't even compile it so was an easy thing to miss). That will fix the error. From here you should add some error handling for practice.
Ok that fixed that. On the command "What numbers from the list do you want to see?, It asks me a question like 1-5,1-6. I don't get that part? And whatever answer i Enter the program exits.
C.B. is offline   Reply With Quote
Old Jul 10th, 2007, 7:52 AM   #14
Ben.Dougall
Programmer
 
Ben.Dougall's Avatar
 
Join Date: Jul 2007
Location: London, Ontario, Canada
Posts: 34
Rep Power: 0 Ben.Dougall is on a distinguished road
Send a message via MSN to Ben.Dougall
put either std::cin.get() or system( "pause" ) after the cout for the number to be displayed.

std::cout << numbers[choice - 1] << std::endl;
system ("pause");

Like i said, i did this at work where I'm not even suppose to be coding, so didn't test it.
Ben.Dougall is offline   Reply With Quote
Old Jul 10th, 2007, 8:14 AM   #15
C.B.
Newbie
 
Join Date: Apr 2007
Posts: 9
Rep Power: 0 C.B. is on a distinguished road
Thumbs up

Quote:
Originally Posted by Ben.Dougall View Post
put either std::cin.get() or system( "pause" ) after the cout for the number to be displayed.

std::cout << numbers[choice - 1] << std::endl;
system ("pause");

Like i said, i did this at work where I'm not even suppose to be coding, so didn't test it.
Awsome.

#include <iostream> 
#include <ctime> 
#include <cstdlib>

using namespace std;

int main() 
{ 
    srand((unsigned)time(0)); 
    int random_integer; 
    int lowest=111, highest=999; 
    int range=(highest-lowest)+1; 
    for(int index=0; index<20; index++){ 
        random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0)); 
        cout << random_integer << endl;
        cin.get(); 
    }

I got this to generate 3 digit numbers. I'll mess around with both codes and see what else I can come up with. Once again thanks to everyone that has helped me.

How can I get the number selector one to select a random number?
C.B. is offline   Reply With Quote
Old Jul 10th, 2007, 10:43 AM   #16
Ben.Dougall
Programmer
 
Ben.Dougall's Avatar
 
Join Date: Jul 2007
Location: London, Ontario, Canada
Posts: 34
Rep Power: 0 Ben.Dougall is on a distinguished road
Send a message via MSN to Ben.Dougall
This thread may help you with the random numbers.

For the picking a random number, just do what i dod for the above program, store the numbers in a array/vector ( vector is better ). Then pick the nth number from the vector.
Ben.Dougall is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM
Creating a program to test a program sixstringartist C 8 Jan 21st, 2006 1:15 PM
move program console window back badbasser98 C++ 21 Oct 18th, 2005 2:02 PM
Nonsense Name generator program chillster13 C 14 Jun 17th, 2005 2:05 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC