![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 15
| im working on an excercise which wants the user to input a number of the numbers to work out a sum of, and then to ask for each number in turn... the program should print out the standard deviation, error in the mean sum of n numbers and sum of their squares. this is what i have soo far. Code: #include <stdio.h>
int main(void);
double i; // variable for each number in turn
char n;
int s; // sum
int s2;// square of the sums
int sdeviation;// standard deviation
int error; // error in the mean
printf("Write the number n of numbers: ");
scanf("%c ", &n);
for n>=0 {
printf("Write each number in turn: ");
scanf("%lf ", &i)
}
s = x++; // this my code for the sum of n numbers
s2 =(x*x)++; // the squares of the sum added together
sdeviation = sqrt(u2 - (u*u)); // formula for standard deviation
error = sdeviation/sqrt(n); // formla for the error in the mean
any help is appreciated very much! |
| abdi_84 is offline | |
| | #2 | |
| Registered User Join Date: Oct 2006 Location: Canada
Posts: 848
| Code: int main(void); Code: int main(void)
{
// stuff here
return 0;
}
Code: for n>=0 Code: for (n>=0) {
Quote:
| |
| nadroj is offline | |
| | #3 |
| Registered User Join Date: Sep 2006
Posts: 2,512
| This program is badly messed up. You get the number n, and use it in a malformed for loop (with critical parts missing), to get the i variable, which is never used. ![]() Then it starts referring to x, which is not even declared as a variable. Even your line declaring int main is defective, with a semi-colon, and no curly brace surrounding it's code. Before you type up code, you need to go back and read your book. You have badly jumped ahead, and missed out on all the important basics. You can't begin to salvage this code. |
| Adak is offline | |
| | #4 | |
| Registered User Join Date: Nov 2009
Posts: 15
| Quote:
i've corrected the int main problem which was a typing error the variable x is actually n, so i changed that moving on heres my malformed for loop.. Code: for (n>=0) {
printf("Write each number in turn: ");
scanf("%lf ", &i)
}
| |
| abdi_84 is offline | |
| | #5 |
| Registered User Join Date: Oct 2006 Location: Canada
Posts: 848
| Cprogramming.com Tutorial: Loops Also you could read other topics here Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy |
| nadroj is offline | |
| | #6 | |
| Registered User Join Date: Nov 2009
Posts: 15
| Quote:
| |
| abdi_84 is offline | |
| | #7 | |
| Algorithm Dissector Join Date: Dec 2005 Location: New Zealand
Posts: 2,476
| May I suggest a change in your programming methodology please? What you need to do is to start with a program that compiles. Basically start with the empty main program and compile that. Then as you go, add bits and compile again after every few lines you add. If something wont compile, fix the obvious bugs or undo your last changes until it compiles again. Don't add more until what you have already compiles. You shouldn't get as far as you have now without having compiled it successfully about 4 or 5 times (given your current ability level). On top of that, you should probably run your program after every few compiles as well, so that you know the code is doing what you intended it to. That way you wont be stuck with code that has lots of problems and generates a ton of errors that you cannot solve. Quote:
__________________ My homepage Advice: Take only as directed - If symptoms persist, please see your debugger | |
| iMalc is offline | |
| | #8 | |
| Registered User Join Date: Oct 2006 Location: Canada
Posts: 848
| Quote:
| |
| nadroj is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sum of numbers | kenjiro310 | C++ Programming | 3 | 10-31-2009 02:48 AM |
| Ping and Traceroute not working in IPv6 environment on Windows XP / Win Server 2003 | vigneshp | Networking/Device Communication | 8 | 05-07-2009 11:31 AM |
| Help With Stacks | penance | C Programming | 7 | 10-09-2005 02:47 PM |
| Argh! Need help with program to get sum of integers between m and n inclusively | Niloc1 | C Programming | 5 | 03-12-2002 01:06 PM |
| Homework help | Jigsaw | C++ Programming | 2 | 03-06-2002 05:56 PM |