Thread: help me

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    1

    help me

    hey I've been working on this for a long time now. I'm trying to have the user input a value for my exponent in an equation and all the other exponents would become one less of the one the user input (such as if the user input a 6 for an exponent, the print statement would read as 6, 5, 4, 3, 2, 1). I know I have to do a for loop and store the values in an array but I keep getting my print statement just saying 0. any suggestions?


    Code:
    
    
    int main(void)
    {
    
    
    double func(double expo);
    double expo;
    
    
    
    
    
    
    
    
    
    
    
    
    printf("\nyour exponents are: %d", func(expo));
    
    
    
    
    
    
    }
    
    
    
    
    double func(double expo)
    {
    		double array[100];
    		printf("\nenter the value for the largest integer exponent: ");
    		scanf("%d", &expo);	
    	
    
    
    	for(int i = 1; i <= expo; i++)
    	{
    		
    		expo = array[i];
    		
    		while(i != expo)
    		{
    		printf("\n%d", array[i]);
    		}
    		
    	}
    	return expo;
    	
    	
    
    
    }

  2. #2
    Registered User
    Join Date
    Oct 2017
    Posts
    39
    You have the function part correct, but inside the function, you need to have the user scan in the highest exponent degree so you know how many terms in f(x).

    Ex: User inputs highest exponent: (3) ---> f(x) = ax^3 + ax^2 + ax^1 + ax^0

    Secondly, you need the user to input coefficients for the number of exponents + 1 (because of x^0) ; I suggest a for loop.

  3. #3
    Registered User
    Join Date
    Jun 2017
    Posts
    88
    At the risk of sounding unhelpful I'll say that debuggers are great. There is a lot of code here that your debugger would help you with. Probably the most important lessons you can learn in programming have to do with learning the debugger.

  4. #4
    Banned
    Join Date
    Aug 2017
    Posts
    861
    if all you are doing is getting the 'number' exponent = 6 then just need to count down starting from that number. why is their an array?

    if you have ten fingers (digits) between two hands, and someone says start from 8 than count down from that number. What number do you start with then count down from that, and do you put that number in your pocket then pull out one less number to count if off then discard it, or count down from that starting point then put that number already counted into your pocket?

    your pocket represents the array. and I must be missing some part of that in which what you really have to do. that is too easy. a teacher would never give out such an easy assessment.


    just take that number put in by user then subtract one from on until it reaches zero. no array needed. so I think you're maybe leaving out something in your explanation on what you need to do in here.
    Code:
    input = 10
    
    loop until input == 0
    input--
    print( input )
    as far as array's go and putting in values and getting out values from an array. you have one array in a for loop putting values into its elements. then another loop, that just happens to be a while loop inside of the for loop. Why?
    Code:
    double array[100]; // declared here, the elements inside of it
    // are 'dead' empty, nothingness, bad values, because it has
    // not been cleared out. initialized.
    
    
       for(int i = 1; i <= expo; i++)    {
      
    // what value do you think is in your array[ i ] element?
    // now it is doing what to your variable called expo? 
    
     //  assignment goes from left to right, yes/no?
    //or
    // assignment goes from right  to left, yes/no?
      // I try to think of it as a backwards math equation. 
    
    // 5 + x = 10 // proper writing
    // 10 = x + 5  // backwards writing
    
    // now we have your empty array and a variable with
    // a value within it. 
    
            expo = array[i]; 
             
    
    
    
    // then down in your other while loop inside of a for loop with the for loop 
    // already controlling the amount of elements it looks into 
    // you're now trying to print out what is inside of the array, when 
    // something went awry in your code above concerning your array.
    //
    // furthermore the use of a  while loop inside of this for loop.
    // does it really need to be like that to get the values printed
    // out of it, or is it over kill ?
    
            while(i != expo) 
            {
            printf("\n%d", array[i]);
            }
             
        }
    and your method of going from down to, that value and how to get that value needs to be thought about more. You are adding to, not subtracting from within that loop.

    So would not your start point need to be set at a larger value, then the condition needs to read so that it will keep it from going negative, then
    to increment or de-increment would be the question that needs to be answered?

    plus
    Code:
     printf("\nenter the value for the largest integer exponent: ");
    you're saying integer and using float. I just find that a bit curious.
    Last edited by userxbw; 10-30-2017 at 08:30 AM.

Popular pages Recent additions subscribe to a feed

Tags for this Thread