User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,641 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1690 | Replies: 3
Reply
Join Date: Oct 2004
Posts: 3
Reputation: NAjAM AHMeD is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NAjAM AHMeD NAjAM AHMeD is offline Offline
Newbie Poster

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

  #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)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,017
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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

  #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.
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Oct 2004
Posts: 3
Reputation: NAjAM AHMeD is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
NAjAM AHMeD NAjAM AHMeD is offline Offline
Newbie Poster

Power, fatorial and modulus syntx

  #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  
Join Date: Sep 2004
Posts: 6,017
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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

  #4  
Oct 27th, 2004
Power is a function declared in the <cmath> header:
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
  cout<< pow ( 2, 4 ) <<endl;
}
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:
#include <iostream>

using namespace std;

int factorial ( int n )
{
  int r = n;

  while ( --n > 0 )
    r *= n;

  return r;
}

int main()
{
  cout<< factorial ( 5 ) <<endl;
}
Member of: Beautiful Code Club.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:08 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC