![]() |
|
#1
|
||||
|
||||
Working with strings and arrays.Hi everyone. Back again, unfortunately
I've got to put together a calculator sort of program. The calculator works by reading a text file provided by the user that is filled with commands. The program then outputs those files into a new text file named by the user. Here is a sample of how it works if commands.txt reads : \ Add 2100000 Add 500 Add 1001 out.txt or whatever the user names the output file will read: Adding 2100000 Result: 2100000 Adding 500 Result: 2100500 Adding 1001 Result: 2101501 I was told to use an array to go through the digits one by one after converting them from strings to int. I'm working on the addition right now and I'm sort of stuck. Here is what I've come up with so far. CPP / C++ / C Code:
Last edited by admin II : 09-May-2008 at 04:34.
Reason: Changed [CODE] to [CPP]
|
|
#2
|
|||
|
|||
Re: Working with strings and arrays.i am not sure if this is what u need if it is not good enough u may wanna post the problem with more details, i am new my self to c++
CPP / C++ / C Code:
|
|
#3
|
||||
|
||||
Re: Working with strings and arrays.Quote:
One thing I notice is you call the DoAddition() function with no parameters. How does the function know what to add? And where is it? It's not even defined. To program this easier, from main() 1) Call a function to simply read the file and return with the line read as a string 2) Call a convert function to return the number portion as an integer value 3) Call a calculate function to perform the calculation, return the total 4) Call an output function __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#4
|
||||
|
||||
Re: Working with strings and arrays.I have an insert function using an array with size 5. I want to throw as many numbers as I want into it only keeping the most recent five.
How would I move everything back in the array one spot so I could drop off the first element and put the new element in the fifth spot? I was thinking something like CPP / C++ / C Code:
I don't even know if that works, but if it does, is there a cleaner way to do it? |
|
#5
|
|||
|
|||
Re: Working with strings and arrays.Quote:
CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
Re: Working with strings and arrays.it is going to be a for loop as i see fakepoo did but if u assignement post un example like if u wanna insert five new entry at the time so i can figure out what we need to do exactly do u wanna integrate this in a unction or the main() will take of it
|
|
#7
|
||||
|
||||
Re: Working with strings and arrays.Okay, now if I was to continuously add numbers to the array and at any given time I wanted to know which element was the newest element in the array, I would just search the array right?
|
Recent GIDBlog
Toyota - 2008 July Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Somebody help with codes for Strings and Arrays | raslou | Java Forum | 1 | 04-Nov-2006 15:35 |
| ? re strings as character arrays function | earachefl | CPP / C++ Forum | 9 | 25-Apr-2006 16:59 |
| Dynamic vs Static Arrays | WaltP | Miscellaneous Programming Forum | 5 | 16-Feb-2006 15:54 |
| I am reviewing Arrays and need help converting some strings to arrays | jenmaz | C Programming Language | 22 | 22-Nov-2004 23:26 |
| Strings and arrays in C | crystalattice | C Programming Language | 5 | 11-May-2004 19:01 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The