I have put this post up in another forum, but it seems as though this one is more active, so I will try my luck here.
Say I am ultimately interested in creating something like a BINGO game. (pretty dumb, but work with me :)
Moreover, say the program reads from an input file that contains the string of numbers called written in the form "B05, I22, N34, B12 etc." Here are some questions I have in trying to do this:
1. How would I manipulate this from reading it off the input? Is there some kind of way to just drop the letters so I can work with straight up numbers? How would you treat such an input?
2a. How do I work with variable sized input files? Say for instance I wanted to have one input file that read 10 numbers, and another 20 numbers (so I wanted a program that was not dependent on a specific input file size or length).
NOTE: Assuming order is not important (primitive version), I am meaning to just be able to read a file like:
B05 I22 N36
B12 I16
B11
obviously that would not be a bingo, but this is just to demonstrate what the input file might look like (but again, it varies in size ... if one number is in the input it should never be a bingo, and if 75 are, then obviously there will be many bingos).
2b. Having worked a lot with Matlab, is there a way to perform operations on rows/columns of arrays? I may have missed this in the tutorials... but for instance, say I wanted to take a randomized input file like the one above, and sort it in an ascending order per column.
2c. In the same fashion as 2b., this goes outside the realms of this 'BINGO' game but will help my general understanding with IO in cpp, what if I had an input file like this:
House Cats Dogs Total
1 1 2 3
2 2 0 2
3 3 5 8
4 9 0 9
Say I wanted to read from this input file and store this information into an array. Is there a way (thinking in SQL terms now) to sort this array based on the value in "Total" so it will be recognized as
House Cats Dogs Total
2 2 0 2
1 1 2 3
3 3 5 8
4 9 0 9
Basically, I am trying to get over the hump of conceptualizing how to store/read/write data in cpp with IO. I am really accustomed to some other langs (matlab for instance) where it is very easy to store data and read data from matrices into new arrays.
Thanks in advance for any help on any of these questions. I greatly appreciate it... I am out of school now but putting in some time to learn cpp and trying to do my own exercises (that i randomly think of). Appreciate it!
hey, u could use the getline function to first get the total input entered by the user, then use nested if statements to check the number of characters in the input, if the first character is a valid letter and if the last two are valid numbers. You can chose to output error statements for whatever error may be in the input and ask the user to enter their choice again. Hope this helps.