User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,570 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,604 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 777 | Replies: 7
Reply
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

read from file help

  #1  
Oct 27th, 2007
I am looking to make a small program for a friend who likes to play roulette. I am looking to make a program that reads from a file which contains numbers (the numbers that come out in roulette) and then counts the amount of numbers that fall in certain groups.

For example, I am going to have 3 groups of numbers...(1,4,7,10,13,16,19,22,25,28,31,34) and (2,5,8,11,14,17,20,23,26,29,32,35) and (3,6,9,12,15,18,21,24,27,30,33,36)

Now let's say my file contains the following numbers:
1
5
22
4
24
35
21
2
8
19
24
34
36
23
1

Then I want to read through that file and print out how many of those numbers fall in which of the three groups above. So based off of this example, there would be 6 numbers in that first group of numbers above (1,5,4,2,8,1)....there would be 6 numbers in that second group above (22,24,21,19,24,23)....and there would be 3 numbers in that third group above (35,34,36).....

So I want the program to print out:
There are 6 numbers in the first group
There are 6 numbers in the second group
There are 3 numbers in the third group

Can anybody help me?? I know this is easy, but I am just getting my feet wet. By the way, this is not a homework assignment. It is simply for fun. We are going to the casino tomorrow night so I want to use this program to count up which numbers come out and keep some stats.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,018
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 6
Solved Threads: 68
ithelp ithelp is online now Online
Veteran Poster

Re: read from file help

  #2  
Oct 27th, 2007
Why do you want to read it from file, cannot you get use rand() to get a random number ?
Reply With Quote  
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: read from file help

  #3  
Oct 27th, 2007
Hi, I want to be able to enter in the actual numbers that come out on the table. We are going to actually write them down so we can see actual stats.
Reply With Quote  
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: read from file help

  #4  
Oct 27th, 2007
basically i am looking for something along the lines of
if(n == 1|4|7|10|13.....etc)
then do work
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: read from file help

  #5  
Oct 27th, 2007
Have you come across the STL yet?
Reply With Quote  
Join Date: Jul 2007
Posts: 54
Reputation: tracethepath is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 4
tracethepath's Avatar
tracethepath tracethepath is offline Offline
Junior Poster in Training

Re: read from file help

  #6  
Oct 27th, 2007
sorry but i dont know the game...
so can i have a little bit of information??
are the three groups fixed and already made??

if so what you can do is first read a integer from the file while(!end of file)
and then compare

let the read integer be n
if(n==1|4|7|10|13...etc)
group1+=1;

else if(n==2|5|8|..etc)
group2+=1;

else(n==3|6|9..etc)
group3+=1;
where group1, group2, group3 are already initialised to 0...

hope this helps...
With Regards...
Reply With Quote  
Join Date: Oct 2007
Posts: 63
Reputation: still_learning is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
still_learning still_learning is offline Offline
Junior Poster in Training

Re: read from file help

  #7  
Oct 27th, 2007
The game is played like this: There is a table with a bunch of numbers on it. They are divided into three groups of numbers. There is also a wheel that spins which has every number on it. A ball is dropped into the spinning wheel and then what ever number it falls into, is the number that I want to keep track of. We want to keep track of about 50 spins, so we will get 50 numbers. Then we just want to be able to enter the 50 numbers into a file, save the file, and run the program.
Reply With Quote  
Join Date: Jul 2007
Posts: 54
Reputation: tracethepath is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 4
tracethepath's Avatar
tracethepath tracethepath is offline Offline
Junior Poster in Training

Re: read from file help

  #8  
Oct 28th, 2007
so you want to enter the numbers for a particular group too for each run..??

to save the 50 numbers in the file you can simple use the following code...

   int n;
   ofstream file1("EXAMPLE.dat", ios::binary|ios::app);
   cout<<"\n\n\t\tADDING RECORDS";

   for ( int i = 0; i < 50;  ++i)
   {
      cout<<"Enter "<<i+1<<" number";
      cin>>n;
      file1<<n;      
   }
   file1.close();

n to compare you can use

if(n==1|4|7|10|13...etc)
group1+=1;

else if(n==2|5|8|..etc)
group2+=1;

else(n==3|6|9..etc)
group3+=1;

i hope this helps
With Regards...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC