English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am trying to write a program that takes in 5 numbers from a user and then add the numbers to get the sum.
I declared
int a,b,c,d,e,sum; so that those would be my varibles.
I get all the numbers typed in in the program but the addition part makes no sense.
I tried
%d=%d+%d+%d+%d+%d, &sum, &a, &b, &c, &d, &e;
I get a bunch of errors saying syntax error found. found 'd' expecting";"
Your help is greatly appreciated.

2007-02-09 07:10:06 · 4 answers · asked by schrickhellcat 1 in Computers & Internet Programming & Design

4 answers

You seem to be mistaking the printf statements of "%d=%d+%d+%d+%d+%d", &sum, &a, &b, &c, &d, &e being valid for if and for statements, etc. The printf statements only work with printf.

Similar to your other question, you only need to use the variables themselves.

sum = a + b + c + d + e;

You will probably only want to display the sum, so use
printf( "%d", sum);

2007-02-10 22:58:33 · answer #1 · answered by Mark aka jack573 7 · 0 0

what is this % sign for? & sign means the address of a variable in memory.

here is what you may want:

int main()
{
int a,b,c,d,e,sum;

// the part which takes in 5 numbers

sum=a+b+c+d+e;

// print out
return 0;
}

2007-02-09 15:16:39 · answer #2 · answered by Poco Metis 2 · 0 1

is that supposed to be a printf? lose the address refs in your variables. (get rid of the "&"s)

sum = a+b+c+d+e;
printf("%d = %d + %d + %d + %d + %d", sum, a, b, c, d, e);

2007-02-09 15:21:08 · answer #3 · answered by javier 2 · 1 0

What are you using to comile? Visual studio or? Try www.programmersheaven.com for some help.

2007-02-09 15:44:12 · answer #4 · answered by micaso1971 5 · 0 1

fedest.com, questions and answers