![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 4
![]() |
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;
} |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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;
}
__________________
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 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
you used the code tags, why didn't you indent?!
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
#6 | |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
Quote:
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 |
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
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. |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
@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;
}#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. |
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 4
![]() |
thanx very much....
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|