Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 5th, 2005, 2:35 PM   #1
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 4 boraciner is on a distinguished road
it doesn't display "sum" on the screen :( HELP ME PLEASE!

this program didn't work .. it doesn't display "sum" on the screen.... help me!!
#include <iostream.h>
#include <stdlib.h>



int main()
{

double a,b,c,d,cd,faka,fakb,sum,fakcd,j;


a=1;
b=4;
c=8;
d=6;


while(b<=37)
{
cd=c*d;
while(a>0)
{ faka=faka+(a*(a-1));
a=a-2;
}
while(b>0)
{ fakb=fakb+(b*(b-1));
b=b-2;}
while(cd>0){
fakcd=fakcd+(cd*(cd -1));
cd=cd-2;
}


sum=sum+( faka+(j*fakb) / (-j*fakcd));

a=a+2;
b=b+3;
c=c+2;
d=d+1;
}



cout<<"sum = "<<sum<<endl;

 system("PAUSE");
  return 0;
}
boraciner is offline   Reply With Quote
Old Nov 5th, 2005, 3:22 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Describe the failure with more clarity. For instance, does it not display "sum = ", or does it not display the sum value, or does it not display anything at all. Quite frankly, your clarity sucks, both as to your question/information, and you coding style. Not a good indicator for successful employability in the long run.

Also, header files ending in ".h" are mostly deprecated. Use the extensionless versions, like iostream and cstdlib.

That said, look at this (which is uglier than my ex-mother-in-law):
while(b<=37)
{
cd=c*d;
while(a>0)
{ faka=faka+(a*(a-1));
a=a-2;
}
Where, in that loop, are you manipulating "b" so that it ever changes value and becomes greater than 37, thus causing the loop to terminate?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 5th, 2005, 5:17 PM   #3
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 4 boraciner is on a distinguished road
My program has to compute that equation -->


1! - 4! / (8*6)! + 3! + 7! / -(10*7)! + 5! - 10! / (12*8)! + ... + n! + 37! / -( n1! * n2!)


my b is displayed as 37!
boraciner is offline   Reply With Quote
Old Nov 5th, 2005, 5:44 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You failed to answer the question. Please gather your thoughts and post appropriately. Please read the "How to Post..." thread and think about the contents. You are sitting before your machine, frustrated, but knowing all that you see. Until our crystal balls are returned, we have no choice but to rely on you for communication.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 5th, 2005, 5:49 PM   #5
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
you used the code tags, why didn't you indent?!
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Nov 5th, 2005, 6:25 PM   #6
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
Quote:
Originally Posted by boraciner
1! - 4! / (8*6)! + 3! + 7! / -(10*7)! + 5! - 10! / (12*8)! + ... + n! + 37! / -( n1! * n2!)
Are you sure you got your parenthesis right with regards to operator precedence?

Rearranged that looks like:

1! + 3! + 5! + 7! + 9!....+ 23! - ( 4!/48! + 7!/70! + 10!/96! + ... 37!/510! )

The right side is so ridiculously small it can be neglected. Leaving basically 23! plus a little
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Nov 6th, 2005, 1:26 AM   #7
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
the code is a mess, you need to use better variable names unless you're writing an entry for the ioccc
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Nov 6th, 2005, 10:41 AM   #8
nindoja
Programmer
 
Join Date: Jun 2005
Posts: 92
Rep Power: 4 nindoja is on a distinguished road
@Dawei: Here is the code you referred to:
while(b<=37)
{
cd=c*d;
while(a>0)
{ faka=faka+(a*(a-1));
a=a-2;
}
while(b>0)
{ fakb=fakb+(b*(b-1));
b=b-2;}
while(cd>0){
fakcd=fakcd+(cd*(cd -1));
cd=cd-2;
}
He modifies b in the while loop right after that, it's just hard to see because of lack of indentation. That said, here is a "prettier" version of the code above for the rest of the people (code was not changed or fixed except a comment to dawei):
#include <iostream.h>
#include <stdlib.h>

int main()
{
    double a,b,c,d,cd,faka,fakb,sum,fakcd,j;
    a=1;
    b=4;
    c=8;
    d=6;

    while(b<=37)
    {
        cd=c*d;
        while(a>0)
        { 
            faka=faka+(a*(a-1));
            a=a-2;
        }
        while(b>0)                 // Dawei: here is where he modifies b
        { 
            fakb=fakb+(b*(b-1));
            b=b-2;
        }
        while(cd>0)
        {
            fakcd=fakcd+(cd*(cd -1));
            cd=cd-2;
        }

        sum=sum+( faka+(j*fakb) / (-j*fakcd));
        a=a+2;
        b=b+3;
        c=c+2;
        d=d+1;
    }

    cout<<"sum = "<<sum<<endl;

    system("PAUSE");
    return 0;
}

@OP: Your problem is that you do a while loop to decriment b to zero, then you add 3 to b and repeat. This causes b to go from 4 to 3 to 2 to 1 to 0 (quit loop) then to 3 (b=b+3 then 3 to 2 to 1 to 0 ......... for infinity. That is your problem, now you go and try to fix it.
nindoja is offline   Reply With Quote
Old Nov 6th, 2005, 11:09 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Put this in the back of your mind: the majority of the money spent on a professional software product is spend after the software is "finished", on maintenance (fixes, new bells and whistles, modifications, and modernizations). Someone, generally not the original programmer, has to work with that shit. It's never too soon to form good habits, unless you're just effing around. If you're looking for outside help, you're not just effing around.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 8th, 2005, 1:22 PM   #10
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 4 boraciner is on a distinguished road
thanx very much....
boraciner is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC