Last edited by Subsonics; 09-24-2011 at 05:24 PM. Reason: In your case you might also need system() in there.
you are totally correct I didn't realize that thanks... I'm working on square root right now but I will go back and try and fix that.
this is what I have for square root
Code:/* square root the number #3 */ sqrt=sqrt(number); printf("%d is the square root of that number\n",sqrt);
Nope... look how I did it in message #30 ... copy the form of that, using the new math.
Also note that sqrt() is for floating point numbers and you're working with integers.
(You really gotta get into the habit of looking this stuff up!)
And, you can't use function names as variables...
there is something wrong again... and I can't figure out why its doing it....
this is my program so far....
it works fine until I added the last part to get it to do the factoralCode:#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int number, cube, sqrot ,i ,sumx ,fact ; printf(" enter a positive number between 1 and 10:"); scanf("%d",&number); if( (number < 1) || (number > 10) ) { printf("The number is out of range. (1-10)\n"); return 0; } /* Check to see if number is odd or even #1 */ if ((number & 1) > 0) printf("%d is odd\n",number); else printf("%d is even\n", number); /* cube the number #2 */ cube=number*number*number; printf("%d is the cube of that number\n",cube); /* square root the number #3 */ sqrot=sqrt(number); printf("square root of that is %d\n",sqrot); /* Sum of the digits #4 */ sumx=0; for (i=1;i<=number;i=i+1) sumx =sumx + i; printf("the sum of the digits is %d\n", sumx); /* Factorial of the number #5 */ fact=0; for (i=1;i<=number;i=i+1) fact=fact*i printf("the factorial of that number is %d\n",fact); system("PAUSE"); return 0; }
when that is added it jumps back up to the sqrot and says it has an error? Grrr I will get this program right it might take me all night but ya!!!! thanks again for help.Code:/* Factorial of the number #5 */ fact=0; for (i=1;i<=number;i=i+1) fact=fact*i printf("the factorial of that number is %d\n",fact);
Ok... what EXACTLY is it doing or not doing?
What error messages are you getting?
What warnings/errors are your compiler listing?
All this is good information... "It doesn't work" tells us nothing.
You are missing a semicolon after fact*i.
true it says
In function 'int main()';
line 28 waring converting int to double
expected' before "printf"
[build error] error 1
I'm guessing its because I didn't use a double of the sqrt which is weird because it worked before and only stopped working when I added the factorial. Can I use int and double for the number they input? If so how do I do that correctly so it works the way I want it to?
-thanks again Cess
lol I can't believe I missed that simple ;
shoot
its sayin the factorial is zero.... so I'm still doing something wrong
I need it to give the factorial of the person's input
Code:/* Factorial of the number #5 */ fact=0; for (j=number;j<=number;j=j+1); fact=fact*j; printf("%d is the factorial\n",fact);
Last edited by Cess; 09-24-2011 at 06:28 PM.
You initialize fact to zero, then you multiply that with i. What happens when you multiply something with zero?
ok now I'm getting 6....I don't understand how I am spost to set it up differently
and I get 3 when I entered 2 and its spost to be 2....Code:/* Factorial of the number #5 */ fact=number; for (j=1;j<=number;j=j+1); fact=fact*j; printf("%d is the factorial\n",fact);
Code:/* Factorial of the number #5 */ fact=1; for (j=1;j<=number;j=j+1); fact=fact*j; printf("%d is the factorial\n",fact);
It's the semicolon again, your for loop runs empty. what you have is the same as:
Code:for(j = 1; j <= number; j=j+1) ;