•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,018 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 1,712 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: 262 | Replies: 3
![]() |
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
In the code below i can'f figure out how to get the numbers from my inFile that will be reversed then put into my outFile. I left part of the code unfinished. not sure what I am supposed to put in between >> >>. pretty lost on this one. Im new at this so go easy. Thanks
language Syntax (Toggle Plain Text)
[icode] #include <iostream> #include <string> #include <fstream> using namespace std; std::string word[5]; int main () { //Declaring Variables ifstream inFile; ifstream inFile1; ofstream outFile; int item[5]; // An array item of 5 components int counter; int num, num1, num2, num3, num4; inFile.open("numbers.txt"); inFile1.open("words.txt"); outFile.open("numberout.txt"); for (counter = 0; counter < 5; counter++) { inFile >> num >> num1 >> num2 >> num3 >> num4; } for (counter = 5; counter >= 0; counter--) { // unfinished code outFile << << endl; } [/icode]
Last edited by greyghost86 : Jul 19th, 2008 at 6:25 pm.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,876
Reputation:
Rep Power: 11
Solved Threads: 193
You need to rethink why you are using a loop.
Ideally, if you have to do things multiple times, it suggests a loop and/or an array.
Since you need to remember five numbers, instead of writing:
you can instead just use an array:
I would have named it "numbers":
(But I'll still use "items" below.)
Now below, you want to read 5 numbers (and remember them). You've got a nice loop there that counts from 0 to 4, and a nice array, so let's put them together:
You've already got a nice loop there that counts from 5 to 0. You'll have to fix that five to the proper number to start at. (Remember, arrays are index from 0 to N-1, where N is the number of elements in the array.) And I think you should know by now what goes inside the loop.
Hope this helps.
Ideally, if you have to do things multiple times, it suggests a loop and/or an array.
Since you need to remember five numbers, instead of writing:
int num, num1, num2, ...you can instead just use an array:
int items[ 5 ];I would have named it "numbers":
int numbers[ 5 ];(But I'll still use "items" below.)
Now below, you want to read 5 numbers (and remember them). You've got a nice loop there that counts from 0 to 4, and a nice array, so let's put them together:
C++ Syntax (Toggle Plain Text)
for (counter = 0; counter < 5; counter++) { cin >> items[ counter ]; }
You've already got a nice loop there that counts from 5 to 0. You'll have to fix that five to the proper number to start at. (Remember, arrays are index from 0 to N-1, where N is the number of elements in the array.) And I think you should know by now what goes inside the loop.
Hope this helps.
Last edited by Duoas : Jul 19th, 2008 at 6:32 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- string array issues with storing input (beginner) (C++)
- Initialising (C++)
- Hey Just started new topic with arrays, and having some trouble please help (C++)
- help with sorting program (C++)
- trouble with counting letter from file, please help. (C++)
- fstream to char and int array (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ and VBA
- Next Thread: Opening an .exe file with C++



Linear Mode