![]() |
|
#1
|
|||
|
|||
C++ Help with mathHi everyone, I am new to this site, and very new to C++.
I graduated high school in 1980 and have not had math since and am now faced with an equation I do not understand. When I was in school, the highest math we took was algebra. I would like to write this C++ program, or at least understand it a little better. Please see the attachment. Here is what the problem states: Write an interactive C++ program that computes and outputs the mean and the standard deviation of a set of four integer values that are input by the user. The mean is the sum of the four values divided by 4, and the formula for the standard deviation is in the attachment. Where n = 4, x refers to each of the four values, and the x with the line overit is the mean. If anyone can tell me what the aquation in the attachment means, I'd appreciate it. I do not understand how it is written. I have not seen this style especially the i's on a lower plane. Thank you Alex |
|
#2
|
|||
|
|||
Re: C++ Help with mathQuote:
Your attachment shows a formula written with a summation symbol. Once you know the name of the operation, you can find explanations in lots of places. For example: http://en.wikipedia.org/wiki/Summation. But it's kind of tough looking up something when you don't know what it is called. See Footnote. It's really easy to make a program loop out of the summation: In words, for the part of the problem that is the summation, you might say something like, "Let i go from 1 up to and including n: form the sum of terms (x[i]- xbar) squared." Where it means that i is an integer and i = 1, 2, ..., n. I have used C-language array notation for the subscript, and I used xbar as a name for the symbol that is x with a bar over it. Some people might read it aloud as, "The sum as i goes from 1 to n of the square of the quantity x sub i minus xbar." Does that help? Regards, Dave Footnote: Well, 1980 sounds like a pretty long time ago to some people, I guess (where does the time go?), but the use of the greek capital Sigma as a summation symbol dates back to 1755, I think, when Leonhard Euler introduced it in his work, Institutiones calculi differentialis. So it wasn't really that new, even when old-timers like you were kids. Last edited by davekw7x : 16-Sep-2006 at 00:36.
|
|
#3
|
|||
|
|||
Re: C++ Help with mathThank you
Yes, thank you, this does help me get started. I may post my program once I get it written, maybe you can tell me if I am on the right track. Thanks again. Alex |
|
#4
|
|||
|
|||
Re: C++ Help with mathOK, I have started to code this assignment.
I know that I am all over th eplace with this as I have received several errors. So far I am attemting to compute the mean of 4 numbers. (4 numbers added together and then divided the results by 4). I also need to code the deviation statement next. I have written the code for each number because I have to write the deviation code for each individual number as well. I thought I would include this in the cout and cin statements for each number, for example "The mean of the 4 numbers are, and the deviation of numbers are: firstNumber = (), secondNumber = (), and so on. Can someone please take a look at this and help me with the errors that I am getting and let me know if I am on track? Thanks All Alex CPP / C++ / C Code:
Last edited by admin : 21-Sep-2006 at 09:36.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#5
|
||||
|
||||
Re: C++ Help with mathHi, the first thing you need to do is post your code inside of tags. Please put [ c++ ] and [ / c++ ] (without the spaces) around your code. This will help all of us understand it.
Just looking at it I can see a couple of mistakes. First you declare the variable mean in three different places. You shouldn't do that. You should only declare the variable once. You can not use cmath::abs() in the form you are using it CPP / C++ / C Code:
on this line: CPP / C++ / C Code:
It seems your logic is correct but the notation is off. __________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
|
#6
|
|||
|
|||
Re: C++ Help with mathQuote:
Normally I would respectfully suggest that you post the exact error messages, but the first ones are pretty clear. Well they are clear to someone who has done a lot of programming (and, therefore has seen lots and lots and lots of error messages). Believe it or not, I actually remember the greate confusion that consumed me the first time I tried some stuff like this. I really do. In C and C++, code blocks are enclosed in braces (the '{', '}' thingies that some people call "curly brackets", not parentheses. The statements in the main() function are a block of code. CPP / C++ / C Code:
Now try to compile and see if the error messages are maybe a little meaningful. If you can't understand what the heck they mean (or you can't see how to fix the code), then I suggest you post the exact messages here, along with whatever current code you are using (after whatever changes that you can see how to do). Paste the messages into your post; don't paraphrase. You might also mention what compiler you are using. It may not be obvious from the messages, and sometimes it makes a difference to people who want to help. Regards, Dave |
|
#7
|
|||
|
|||
Re: C++ Help with mathWow great suggestions, thank you.
I will try this tonight and get back with you. Thanks agian, I truly do appreciate the help!!! Alex |
|
#8
|
|||
|
|||
Re: C++ Help with mathHi everyone, it's me again.
You will probably here a lot from me during this class. I must say a have deep appreciation for everyone who understands and has the patience to code, my hats off to you all! First I want to say thatnk you. I have written the code for my program and I am not currently getting any errors. Also, I am not getting any output. I am able to enter the 4 values, but then nothing happens. I am using cout statements. Please let me know what I am missing. Again thank you very very much. Alex |
|
#9
|
|||
|
|||
Re: C++ Help with mathQuote:
You have to show us what you are doing before anyone can tell you what you are doing wrong (or what you are not doing). In other words: show us the code. Regards, Dave |
|
#10
|
|||
|
|||
Re: C++ Help with mathThanks Dave:
Below is my code, but one more question: Should I put the cout statements right below the cin statements rather than together on the bottom? Again I really appreciate you! Alex CPP / C++ / C Code:
Last edited by admin : 21-Sep-2006 at 09:38.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
Recent GIDBlog
Developing GUIs with wxPython (Part 1) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed on visual C++ basic math program | xoBeBExo | C++ Forum | 5 | 18-Nov-2005 01:52 |
| Math function errors | tnethaji | C Programming Language | 1 | 04-Jul-2005 13:22 |
| C math functions | tnethaji | C Programming Language | 1 | 04-Jul-2005 06:03 |
| Beginning C++ math prog | Dariklar | C++ Forum | 6 | 10-Sep-2003 11:51 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The