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

This is a discussion on I'm new taking my 1st class, and I am having trobble with my homework.. help please! within the C Programming forums, part of the General Programming Boards category; Originally Posted by quzah You need to assign the value with =, which you aren't doing, and you don't even ...

1. 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.

2. 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.

3. 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.

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;
}```

4. 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

5. 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);```

6. 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...

7. 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.

8. 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.

9. You are missing a semicolon after fact*i.

10. 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

11. 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);```

12. You initialize fact to zero, then you multiply that with i. What happens when you multiply something with zero?

13. 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);```

14. 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)
;```

15. I am still not understanding.....

Page 3 of 4 First 1234 Last