| nyaeggy (32) | ||
|
I will prepare files of “random” integers for you. The numbers will be stored 1 per line. Your program will: Prompt the user for the name of the datafiles to use (note: you can call your output file anything you want…within reason). While there is data in the file Read an integer If the integer is even, add it to the even sum If the integer is odd, add it to the odd sum Be sure to check for an empty file. If there is, report this to the user and stop the program right there (exit). o When there is no more data, output the sum of the even integers and the sum of the odd integers TO A TEXTFILE. When I compile it doesn't seem to find the text or I may be doing something wrong my ouput:
| ||
|
Last edited on
|
||
| meeram (22) | |
| Check whether the file(Ints1.txt) is located in the same path where your coding class file exists (lets say main.cpp) | |
|
Last edited on
|
|
| nyaeggy (32) | |
| I may sound really dumb here but I saved them on separate files on my documents. | |
|
|
|
| meeram (22) | |
| Whats the path of Ints1.txt and your cpp file? | |
|
Last edited on
|
|
| nyaeggy (32) | |
|
It is on my libraries/documents/Ints1.txt Do i move them to local disc C? | |
|
|
|
| nyaeggy (32) | |
| My cpp file is in libraries/documents/C++/HW9 | |
|
|
|
| meeram (22) | |
| Its just a suggestion, move the .txt file to libraries/documents/C++/HW9 and check whether you are getting the same error or not. | |
|
|
|
| nyaeggy (32) | |
|
I moved them to HW9 and I am still getting the same error. this is how I am calling it: Enter file name: c:\libraries\documents\HW9\Ints1.txt maybe this is where the erros is? | |
|
|
|
| meeram (22) | |
|
Once you moved, give the file name as Ints1.txt. Like, Enter file name: Ints1.txt (instead of full path) | |
|
|
|
| nyaeggy (32) | |
| I get the same output. | |
|
|
|
| LowestOne (767) | |||
The location of the file that code creates is where you need to put your input file. | |||
|
|
|||
| meeram (22) | |
|
I tried and it was working fine...my file paths are C:\wc\test\main.cpp C:\wc\test\Ints1.txt and I have given the file name in the runtime as Ints1.txt. | |
|
|
|
| nyaeggy (32) | |
| Is it possible for you to show the part of the code where you put the location of the file? | |
|
|
|
| meeram (22) | |
| I didn't use the location of the file in my code. I just used your coding and placed the .txt file in the same location of main.cpp and executed. | |
|
|
|
| nyaeggy (32) | |
| That would meant that I wouldn't allow the user to enter the file name if i put it directly on my code. And I need to let the user be able to enter their own file name. | |
|
|
|