|
-
August 26th, 2012, 04:18 PM
#1
[RESOLVED] Reading integers from a data file, and using the integers in formulae
Last edited by mcurley104; August 28th, 2012 at 03:33 PM.
-
August 26th, 2012, 04:24 PM
#2
Re: Reading integers from a data file, and using the integers in formulae
So what have you already done? And what part of the code is "hard" for you?
Victor Nijegorodov
-
August 27th, 2012, 01:15 AM
#3
Re: Reading integers from a data file, and using the integers in formulae
 Originally Posted by mcurley104
...
pretty sure there is some problems with that but thats been my best attempt at starting it
Why are you "pretty sure"?
Did you try to compile this code?
Victor Nijegorodov
-
August 27th, 2012, 03:13 AM
#4
Re: Reading integers from a data file, and using the integers in formulae
Code:
vector<int> x,y;
int x,y,i=1,lines;
You defined x and y twice.
-
August 27th, 2012, 03:19 AM
#5
Re: Reading integers from a data file, and using the integers in formulae
 Originally Posted by Skizmo
Code:
vector<int> x,y;
int x,y,i=1,lines;
You defined x and y twice.
On the other hand there are some undeclared variables:
- sum_of_x;
- sum_of_y;
- c1[ ];
- c2[ ];
Victor Nijegorodov
-
August 27th, 2012, 06:44 AM
#6
Re: Reading integers from a data file, and using the integers in formulae
You must fix all the errors the compiler shows you. Use MSDN to obtain info about compiler errors and their possible causes.
Victor Nijegorodov
-
August 27th, 2012, 07:13 AM
#7
Re: Reading integers from a data file, and using the integers in formulae
 Originally Posted by mcurley104
yeah i am in the middle of doing that, i can't think of what the formula would be to add all of the x values together, any suggestions?
There is no formula. You add them up in a loop, adding to a running total.
Regards,
Paul McKenzie
-
August 27th, 2012, 12:46 PM
#8
Re: Reading integers from a data file, and using the integers in formulae
 Originally Posted by mcurley104
Thanks Paul, i have decided to re-do the structure of the program. this is what i have so far
You need to use code tags when posting code.
What is that supposed to do?
i am just not sure how i could implement a loop to find the sum values for "X, Y, XY and X^2" from the data file?
You don't "find the sum" by doing what you're doing now. Where is the attempt to write the loop?
You're supposed to read in one line at a time, and for each line you read, you add that value to a running total. When all of the numbers are read, those totals you have are the addition of the values.
Have you ever used a simple calculator? How do you add 10 numbers? Is there a huge "ADD" button that adds all the numbers in one go? No there isn't. What you do is that you "loop" -- you enter a number, you press the '+' key, you enter the second number, you enter the '+' key, etc. The program should be mimicking how you enter numbers into a calculator. The total starts out at 0, and then you read the next number and add to the total. By the time all the numbers are read, you have your grand totals.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; August 27th, 2012 at 12:48 PM.
-
August 27th, 2012, 03:13 PM
#9
Re: Reading integers from a data file, and using the integers in formulae
 Originally Posted by mcurley104
... when i compile this it says the "cin"'s and "cout"'s are undeclared identifiers, do you see where i could be getting this problem?
In every such a case you should go to MSDN (in the case of cin it would be cin) and see what header files you have to include and what namespaces you have to use.
Besides, as Paul already mentioned, you have to use Code tags while posting code snippets. Please, read the Announcement: Before you post....
Victor Nijegorodov
-
August 27th, 2012, 05:09 PM
#10
Re: Reading integers from a data file, and using the integers in formulae
here is my attempt to put in a loop,
You still did not put your code in code tags.
first time i have ever done a loop,
Why in all of your loops you're outputing values? Aren't you supposed to be inputing values in the loop?
Step back and take a look logically at what you wrote. Does it make sense to output 21 times some unknown value? Look at this using psuedo-code (and logic).
Code:
0) set all of your totals to 0
1) Open the file
2) While there is data in the file
2a) Read next line in the file
2b) Take the data from that line and add it to the totals
2c) loop again (go back to step 2)
3) End.
Do you see how logically this makes sense? Compare those words above with what you wrote? Did what you write have any resemblance to those steps? After step 3), those totals are going to have the total of the numbers.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|