Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,111 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,740 people online right now. Registration is fast and FREE... Join Now!




C ++ factorial problem.. it wont work

 
Reply to this topicStart new topic

C ++ factorial problem.. it wont work, c++ HELP.... can someone solve this ?? i tried

chilechuck
18 Apr, 2007 - 03:08 AM
Post #1

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 2


My Contributions
SCENARIO 1 : no input parameters, output id line, see the format below.

SCENARIO 2 : two or more command line parameters is an error and the only
output should be "C".

SCENARIO 3 * The command line parameter must be an 8 bit unsigned integer,
if not the output must be "P".
* Given an integer n the output should be the result of the
calculation n!. All calculations should be done using
a standard signed integer ( 32 bit) and the result printed out
using cout then a line feed (\n).
If the calculation proves impossible the output should be "X".

BAKGROUND : note that 0! = 1, 1!=1, 2!=2*1, 3!=3*2*1, 4!=4*3*2*1 .....

I have to use K DEVELOP on linuX i cant get it to work ! ??
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>

using namespace std;

int main(int argc, char *argv[])
{//--- When no parameters MUST print id string in CSV format.
if (argc == 1) // no parameters.
{ cout << "3129072, s3129072@student.rmit.edu.au, Ki Chun Ng"
<< endl ;
return(0) ;
}
if (argc > 2)
{
cout << "C" <<endl;
return(0);
}
int num = atoi(argv[1]);
int result=1;
int inv_EightBit = 0xFF00;

if (argc == 2)
{
if(!num || (num & inv_EightBit))
{
cout << "P"<<endl;
}
else
{
for (int i=1;i<= num ;i++)
{
result = result * i;
}
if (!result)
{
cout<<"X"<<"\n";
}
else
{
cout<<result<<"\n";
}
}

}

//--- START YOUR CODE HERE.

system "pause";
return(0);
}




User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C ++ Factorial Problem.. It Wont Work
18 Apr, 2007 - 07:21 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Please use [code] tags arround you code. It makes it much easier to read.

What exactly is your question?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:43PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month