C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-07-2009, 01:37 PM   #1
Registered User
 
Join Date: Nov 2009
Posts: 15
Post working out the sum of integers

hi
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
i have a few errors, i just need a bit of direction on how to make my program work

any help is appreciated very much!
abdi_84 is offline   Reply With Quote
Old 11-07-2009, 02:06 PM   #2
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 848
Code:
int main(void); 
You do not want a semi-colon here. "main" (in your case) should look like
Code:
int main(void)
{
  // stuff here
  return 0;
}
You dont have open or close brackets either.

Code:
for n>=0
Should be
Code:
for (n>=0) {
And a number of other errors. Though you should fix these, then read through the code to spot these errors.
Quote:
i have a few errors
Though we can probably figure out what the errors are, if you have some then: What are the errors?!
nadroj is offline   Reply With Quote
Old 11-07-2009, 02:06 PM   #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   Reply With Quote
Old 11-07-2009, 02:28 PM   #4
Registered User
 
Join Date: Nov 2009
Posts: 15
Quote:
Originally Posted by Adak View Post
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.
alright

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)
        }
the aim of it is to perform a number of operations on each variable entered by the user, how do i achieve that?
abdi_84 is offline   Reply With Quote
Old 11-07-2009, 02:31 PM   #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   Reply With Quote
Old 11-07-2009, 02:38 PM   #6
Registered User
 
Join Date: Nov 2009
Posts: 15
Quote:
Originally Posted by nadroj View Post
thanks i'll have a read
abdi_84 is offline   Reply With Quote
Old 11-07-2009, 03:34 PM   #7
Algorithm Dissector
 
iMalc's Avatar
 
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:
Originally Posted by nadroj
Code:
for (n>=0) {
No, that wont compile either. I think you're looking for a "while" loop there, but you also need to ensure it isn't an infinite loop as it would be now since n doesn't change in the loop.
__________________
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
iMalc is offline   Reply With Quote
Old 11-07-2009, 03:40 PM   #8
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 848
Quote:
No, that wont compile either. I think you're looking for a "while" loop there
Wow! Im new at this :s.
nadroj is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 07:29 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22