hi... I always having a hard time to debug all my errors.. but still, calling some functions
are the most painful I guess...
Will you help me on how to call some functions?
thank you!
hi... I always having a hard time to debug all my errors.. but still, calling some functions
are the most painful I guess...
Will you help me on how to call some functions?
thank you!
PROJECT2.CPP
#include<iostream.h>
#include<conio.h>
#include<dos.h>
void product(int b,int e)
//this is for the case no.1
int product(int b,int e)
{int x,p=b;
for(x=1;x=e,x++)
p=p*b;
return p;
}//End case no1
//this is for the case no.2
long long int factorial(int no)
{int Loop,F=1;
for(Loop=1;Loop<no;Loop)
{F=Loop*F;
<<Loop;
}
<<F;
}//End case no2
main(void)
{int base,exponent,number,choices;
long long int prod;
clrscr()
gotoxy(10,10);
cout<<"1 Exponent";
gotoxy(15,15);
cout<<"2 Factorial";
gotoxy(20,20);
cout<<"SELECTION: "
cin>>choices;
switch(choices)
{
case 1:
{clrscr();
cout<<"Base: ";
cin<<base;
cout<<"Exponent: ";
prod=product(base,exponent);
cout<<"The product of"<<base;
cout<<"raise to"<<exponent;
cout<<"is"<<prod;
getch();
break();
}
case 2:
{clrscr();
cout<<"Enter a positive Integer: ";
cin<<number;
if(number>0)
factorial(number);
getch();
break();
}
getch();
}
//End the program(I hope so!)
what's not working? what doesn't your program do that you want it to do? You need to explain the problem. Do you take your car to auto repairman and say "Its broke, please fix it"?
nt product(int b,int e)
{int x,p=b;
for(x=1;x=e,x++)
p=p*b;
return p;
}//End case no1
//this is for the case no.2
long long int factorial(int no)
{int Loop,F=1;
for(Loop=1;Loop<no;Loop)
{F=Loop*F;
<<Loop;
}
<<F;
}//End case no2
The above has at least two problems:
line 3: x=e you are using the assignment operator = instead it should probably using the < operator.
line 11: The third part of that loop statement should increment the value of the loop counter -- yours doesn't do anything.
line 13 and 15: I have no clue what those two statements are attempting to do. The << operator doesn't make sense. Maybe you meant ++ (increment operator) ?
I see you use long long data type in several places. To my knowledge TurboC compiler doesn't know what that is. If you want to use long long then you need to use a newer compiler that knows about 64-bit longs.
aah.. now I Know thank you very much... ^_^
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.