Need help with the program i have written i am unable to correct the problems. please

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 3
Reputation: NAjAM AHMeD is an unknown quantity at this point 
Solved Threads: 0
NAjAM AHMeD NAjAM AHMeD is offline Offline
Newbie Poster

Need help with the program i have written i am unable to correct the problems. please

 
0
  #1
Oct 26th, 2004
hello!
i am a brand new user to this site ihope that my experence with this site would be better than previous ones, i am studying BS(computer science), recently i had trouble with a program that ihave made well that thing is that its is complete and working as well but there are problems with it i am sending the program as .cpp file i hope people at dani web will help me in correcting the program most of the problem is with the part where there is modulus and factorial function.
Attached Files
File Type: cpp Program.cpp (2.6 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,728
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 737
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Need help with the program i have written i am unable to correct the problems. pl

 
0
  #2
Oct 26th, 2004
What are you trying to do with those two functions? It's clearly not a simple factorial or modulo calculation, so unless you describe what the problem is, we can't help. Though I can tell you right now that your power function isn't going to work like you expect.

>i=a^b;
^ is the bitwise exclusive OR operator, not the power operator. C++ doesn't have such an operator.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3
Reputation: NAjAM AHMeD is an unknown quantity at this point 
Solved Threads: 0
NAjAM AHMeD NAjAM AHMeD is offline Offline
Newbie Poster

Power, fatorial and modulus syntx

 
0
  #3
Oct 26th, 2004
can anyone tell me what is the syntx for power in c++ as well as factorial and modulus because i am at a begginers stage.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,728
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 737
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Need help with the program i have written i am unable to correct the problems. pl

 
0
  #4
Oct 27th, 2004
Power is a function declared in the <cmath> header:
  1. #include <cmath>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. cout<< pow ( 2, 4 ) <<endl;
  9. }
Modulus does have an operator (%), but it only works for integer values. For floating-point, you need to use the fmod function declared in the <cmath> header.

N! is easy to calculate:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int factorial ( int n )
  6. {
  7. int r = n;
  8.  
  9. while ( --n > 0 )
  10. r *= n;
  11.  
  12. return r;
  13. }
  14.  
  15. int main()
  16. {
  17. cout<< factorial ( 5 ) <<endl;
  18. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC