HELP! (w/C program)

Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
edited October 2003 in Internet & Media
Ok, so I have a lab that was assigned today for my C class, and it's due tomorrow. The requirements of the lab are as follows:

Write a program that uses standard functions. The program may be written entirely in main and must follow the pseudocode below. Give the output appropriate captions, and align the data.

Pseudocode:
1. Prompt the user to enter a number
2. Read number.
3. Display number.
4. Get a random number and scale to range 3...37.
5. Display random number.
6. Set product to number + random number.
7. Display product.
8. Display ceiling of product.
9. Display floor of product.
10. Display number raised to power 5.
11. Display square root of random number.

My code:
#include stdio.h
#include stdlib.h
#include time.h
#include math.h

int main (void)

{
	int user_num1 = 0;
	int rand_num1 = 0;
	int product = 0;

	printf("Enter a number: ");
	scanf("%d", &user_num1);
	printf("\nThe number you entered was: %d", user_num1);

	srand (time (NULL));
	rand_num1 = rand() % 35+3;
	printf("\nA random number: %d", rand_num1);

	product = user_num1 * rand_num1;
	printf("\nProduct of your number x the random number: %d", product);

	double ceil (product);
	double floor (product);

	printf("\nThe ceiling of the product is: %10.2f", ceil);
	printf("\nThe floor of the product is: %10.2f", floor);
	
	pow (user_num1, 5);
	sqrt (rand_num1);

	printf("\nYour number raised to the 5th power is: %10.2f", pow);
	printf("\nThe square root of the random number is: %10.2f", sqrt);
	return 0;
}

It's not completed, but I'm trying to debug it as I go. You can see the issue that I'm running into in the attached screenshot. Any suggestions on why it's doing this?

The compiler is Visual C++ .net student edition, if it matters.

Here's the issue (look at the last few lines of the program):

Comments

  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited October 2003
    :bawling:

    Anyone got any ideas?
  • a2jfreaka2jfreak Houston, TX Member
    edited October 2003
    I told you I was going to sleep, and now I see this thread.

    Blah!

    /me goes to bed!
    #include < stdio.h >
    #include < stdlib.h >
    #include < time.h >
    #include < math.h >
    
    
    
    int main (void)
    
    {
    
    	int user_num1 = 0;
    	int rand_num1 = 0;
    	int product = 0;
    	[b]double exponents = 0;[/b]
    
    	printf("Enter a number: ");
    	scanf("%d", &user_num1);
    	printf("\nThe number you entered was: %d", user_num1);
    
    
    	srand (time (NULL));
    	rand_num1 = rand() % 35+3;
    	printf("\nA random number: %d", rand_num1);
    
    
    	product = user_num1 * rand_num1;
    	printf("\nProduct of your number x the random number: %d", product);
    
    
    
    	double ceil (product);
    	double floor (product);
    
    	printf("\nThe ceiling of the product is: %10.2f", ceil);
    	printf("\nThe floor of the product is: %10.2f", floor);
    	
    
    	[b]exponents = pow (user_num1, 5);
    	printf("\nYour number raised to the 5th power is: %10.2f", exponents);
    	exponents = sqrt (rand_num1);
    	printf("\nThe square root of the random number is: %10.2f", exponents);[/b]
    
    	return 0;
    
    }
    
  • qparadoxqparadox Vancouver, BC
    edited October 2003
    Hope this isn't too late.


    Your problem is in your use of the functions pow and sqrt and the meaning of the statement function(argument). The function pow(), or sqrt() or whatever return data of a set type , however, if you want to want use this in your program you either have to assign the returned value to some variable in your program, or use the value directly. I've included examples of both in the following corrected code:

    double ans = pow (user_num1, 5);

    printf("\nYour number raised to the 5th power is: %10.2f",ans) ;


    printf("\nThe square root of the random number is: %10.2f", sqrt(rand_num1));


    When you called pow(a,b) you just called the function but never did anything with is output.


    Just to be sure (been over a year since i've touched C) I did compile this and it worked on gcc.

    You'll need to correct your use of the pow and sqrt functions accordingly and I'll leave that to you. (Note that I didn't check anything else, i only corrected the error in function use). GL and HF.
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited October 2003
    Thanks for the help guys. I'll try that out tomorrow morning (class starts @ 10:30, I have to leave @ 10, It's too late to work on it now... I'll get up early tomorrow morning and do it). This function thing has really thrown me for a loop. The class was dead easy up until we hit this chapter. Aggh!

    Thanks again.

    //Edit
    Oh, I did have the > and < symbols in there, but for some reason it wouldn't show up. Oh well... :rolleyes:
  • a2jfreaka2jfreak Houston, TX Member
    edited October 2003
    Just copy my code, it works.

    /me really goes to bed, LOL
Sign In or Register to comment.