•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

# Help me sloving this exercise !

This topic has been archived. This means that you cannot reply to this topic.
24 replies to this topic

### #1 ErtanTaboo

ErtanTaboo

CC Newcomer

• Member
• 12 posts

Posted 13 December 2012 - 04:46 AM

Can someone of you help me sloving this exercise in C++ , because I need this to school , and I can't slove because I'm a begineer .

p.s I think you know what "E" stands for !

Thank You !

### #2 neil

neil

• Senior Member
• 373 posts

Posted 13 December 2012 - 07:20 AM

Simple..
do a calculation like y=x/3
then do a loop which calculates the value of the sum of x+2 from 1 until m+n-1.
Then multiply temp by 2. Add temp and y.

(Assuming E is the series summation..)

Try to write that bit of code. If you have a problem, post back.

PS: You should have posted in the homework section if you didn't know there was one

### #3 ErtanTaboo

ErtanTaboo

CC Newcomer

• Member
• 12 posts

Posted 13 December 2012 - 09:27 AM

OH sorry bro but i didn't knew that there was a section like that , te function should be like this(look the photo down) ... sorry , "Writte the program for calculating value of the amount of function"-These are the words in the exercise , but i have no idea how to slove this , if u can write the codes , i will appriciate that !

### #4 gregwarner

gregwarner

Obi Wan of Programming

• Expert Member
• 1586 posts

Posted 13 December 2012 - 09:31 AM

ErtanTaboo, neil already told you how to write the program to solve this. The first thing you should know about Codecall is that we are not going to do your homework for you. You must do it yourself. We are here to help you learn and to teach you so you will develop these skills on your own. Us doing the work for you will not be helpful to you at all.

Start by telling us what you've done so far? How much code have you written?

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

### #5 ErtanTaboo

ErtanTaboo

CC Newcomer

• Member
• 12 posts

Posted 13 December 2012 - 09:50 AM

this is what i did , i that correct ?

```#include <iostream>
using namespace std;
int main ()
{
int m,n,i;
double x,S,Y;
cout<<"value of x , m , n=";
cin>>x,m,n;
S=0;
i=1;
do
S=S+(x+2/i);
i=i+1;
while i>(m+n-1);
Y=x/3+2*S;
cout<<"Amount of function Y="
<<Y
<<"\n";
return 0;
}
```

### #6 neil

neil

• Senior Member
• 373 posts

Posted 13 December 2012 - 09:54 AM

You also need braces to go with your do while statement..
And you forgot to do S*2.
And you printed the wrong variable. Don't you need to print out Y ? (4th last line)

Edit:
Use parenthesis () on the Y=x/3... line to avoid confusion and/or logical errors.

### #7 ErtanTaboo

ErtanTaboo

CC Newcomer

• Member
• 12 posts

Posted 13 December 2012 - 09:58 AM

Where should i do S*2 ?
Yes i edit that 4th last line .
Where should I do braces , on the exercise or while I'm writte , because I'm an Albanian and I don't know English very well !

### #8 gregwarner

gregwarner

Obi Wan of Programming

• Expert Member
• 1586 posts

Posted 13 December 2012 - 09:59 AM

There's a problem with your do while loop. You need to enclose the two statements of the body in burly braces { }. Also, your greater-than comparison on the while line is backwards. It should be less than, because you want to keep looping while i is less than the upper bound.

But do while really isn't the best choice here. Try using a for loop instead.

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

### #9 neil

neil

• Senior Member
• 373 posts

Posted 13 December 2012 - 10:00 AM

edit your do while loop to look like this:
```
do
{
statements;
}while( condition );```
(Edit: or do a for loop as greg says)

And do the S*2 after the loop.

### #10 gregwarner

gregwarner

Obi Wan of Programming

• Expert Member
• 1586 posts

Posted 13 December 2012 - 10:02 AM

And you forgot to do S*2.

He already did, on this line:

Y=x/3+2*S;

And you printed the wrong variable. Don't you need to print out Y ? (4th last line)

He printed out Y.
```cout<<"Amount of function Y="
<<Y
```

Use parenthesis () on the Y=x/3... line to avoid confusion and/or logical errors.

The order of operations in C++ ought to deliver the correct result the way he coded it.

Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

### #11 neil

neil

• Senior Member
• 373 posts

Posted 13 December 2012 - 10:02 AM

greg, he edited his post after i told him.

### #12 ErtanTaboo

ErtanTaboo

CC Newcomer

• Member
• 12 posts

Posted 13 December 2012 - 10:04 AM

you mean like this ?

```#include <iostream>
using namespace std;
int main ()
{
int m,n,i;
double x,S,Y;
cout<<"value of x , m , n=";
cin>>x,m,n;
{
S=0;
i=1;
do
S=S+(x+2/i);
i=i+1;
for
i>(m+n-1);
}
Y=(x/3)+2*S;
cout<<"Amount of function Y="
<<s
<<"\n";
return 0;
}
```

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download