•
•
•
•
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
![]() |
•
•
Join Date: Oct 2004
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
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.
>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.
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:
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 <cmath>
#include <iostream>
using namespace std;
int main()
{
cout<< pow ( 2, 4 ) <<endl;
}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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Another not able to connect with IE after installing Linksys post (Networking Hardware Configuration)
- program help (C++)
- Help-can't boot up "explorer.exe has generated errors..." (Windows NT / 2000 / XP / 2003)
- Classes (C++)
- SLOT MACHINE PROGRAM... Help plsss! (C)
- Translate an algorithm to C program (C)
Other Threads in the C++ Forum
- Previous Thread: dynamic polymorphish in c++
- Next Thread: Error in c++ program



Linear Mode