# I'm new taking my 1st class, and I am having trobble with my homework.. help please!

Show 80 post(s) from this thread on one page
Page 3 of 4 First 1234 Last
• 09-24-2011
CommonTater
Quote:

Originally Posted by quzah
You need to assign the value with =, which you aren't doing, and you don't even have it compilable at the moment:
Code:

```//cube number number = number * number * number;```

Quzah.

Which is going to alter the value of number for the next function.
• 09-24-2011
quzah
Quote:

Originally Posted by CommonTater
Which is going to alter the value of number for the next function.

That's true. I was only solving the immediate problem at hand. Your in-printf solution is more elegant.

Quazh.
• 09-24-2011
Subsonics
Quote:

Originally Posted by Cess
ok I'm getting closer... I got 1 now I'm on number 2 and I need help again Lol thank you guys for being patient and helpful to a newbie like me!
Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h>   int main() {        int number;     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");         /* 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 */       number*number*number       printf("%d is the cube of that number\n");           system("PAUSE"); return 0; }```

Wasn't you also suppose to quit, if a number isn't 1-10? Otherwise you are just carrying on as if nothing happened.

Quote:

Originally Posted by Cess
If an unsuitable number is entered, program exits only printing that an invalid number was entered.*/

Code:

```    if( (number < 1) || (number > 10) ) {         printf("The number is out of range. (1-10)\n");         return 0;     }```
• 09-24-2011
CommonTater
Quote:

Originally Posted by quzah
That's true. I was only solving the immediate problem at hand. Your in-printf solution is more elegant.

Quazh.

Be still my fluttering heart... A compliment from Quzah ... now when's the last time that happened :D
• 09-24-2011
Cess
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);```
• 09-24-2011
CommonTater
Quote:

Originally Posted by Cess
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...
• 09-24-2011
Cess
there is something wrong again... and I can't figure out why its doing it....

this is my program so far....
Code:

```#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; }```
it works fine until I added the last part to get it to do the factoral

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);```
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.
• 09-24-2011
CommonTater
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.
• 09-24-2011
Subsonics
You are missing a semicolon after fact*i. :)
• 09-24-2011
Cess
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
• 09-24-2011
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);```
• 09-24-2011
Subsonics
You initialize fact to zero, then you multiply that with i. What happens when you multiply something with zero?
• 09-24-2011
Cess
ok now I'm getting 6....I don't understand how I am spost to set it up differently
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);```
and I get 3 when I entered 2 and its spost to be 2....
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);```
• 09-24-2011
Subsonics
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)     ;```
• 09-24-2011
Cess
I am still not understanding.....
Show 80 post(s) from this thread on one page
Page 3 of 4 First 1234 Last