/**
 * File:        Homework_I.c
 * Author:      Viktor Akulich
 * Created:     26.09.2018
 * Last edit:   01.10.2018
 *
 * Description: Calculating Function y = f(x)
 *              
 */
#include <stdio.h>
#include <math.h>		//include this labrary for sqrt() and pow() functions
int main(){
	
	int i;				// use this variable for FOR LOOPS 
	float i_func[15];  	//An array of input values of the function
	float out_func; 	//The result of the function if it is possible 
	float A;  			//User input starting point
	float B;  			//User input ending point
	float C;  			//User input step's coefficient 
	float H;  			//User input step
						//use floats because the input and result
						// can be any real number.
						
						
						
						//Ask user different variables values.
	printf("Insert the starting value: \n");
	scanf("%f", &A);	//get the starting value
	printf("Insert the endingg value:\n");
	
	
	
	
	
	while(1)
	{  
		scanf("%f", &B);
		if (B>A)
		{  
			break; 		
		}
		else
		{
			printf("Please repeat!!!!\n");
			printf("Insert the number which is bigger than starting value :\n");
		}
	}
	printf("Insert the step value:\n");
		//Cheak  user input by implementing while loop 
		//it always true because 1 is TRUE 
		//is always True, so the only way to stop it use
		//break statement
		//If it meets the requirement such as B>A then we
		// stop the loop and go to the next loop
		//If it doesn't meet the requrement we ask user
		// to repeat the operation and start the loop from the beginning
	
	
	
	
						
	while(1)
	{
		scanf("%f", &H);
		if (H > 0)
		{		
			break;	
		}
		else
		{
			printf("Please repeat. Insert the number which is bigger than 0:\n");
		}
	}
	
	printf("Insert the step's coeficient value should be >=1:\n");
	while(1)
	{
		scanf("%f", &C);
		if (C>=1)
		{
			break;
		}
		else
		{
			printf("Please repeat. Insert the number which is bigger or equal to one:\n");
		}
	}
	//Do almost the same operations for  step value and its 
	//coefficient as well.The difference is only in the condition after
	//IF statement and text inside PRINTF statement
	
	
	
						
	i_func[0]=A; 		
	for(i = 1; i < 15; i++)
	{		
		i_func[i] = i_func[i-1] + (H * pow(C,(i - 1)));							
	}
	//Create all inputs for the function
	//Create 0th element, which I will use to create other values. 	
	//use for loop in order to fill the array with appropriate values
	//fill each element by adding to previous element C^(i-1)*H,  
	
	
	printf("  x\t\ty\n");			
	//make two colums X and Y by using \t twice 
	//otherwise Y doesn't coinside with numbers
	
	
	
	
	for(i = 0; i < 15; i++){ //use the FOR LOOP to fill two collums with X and 		
							 //Y values, and cheak wheather Y value is exist, Not 
						     //available or it is a complex number 
		
		if (i_func[i] >= B)
		{				//by defenitions the values couldn't 
						//be more than ending point, but it might happen that 
			break;		//when the array was filling in some values exceeded 
						//the ending point(B) so I have to cheak. 
						//if we find the values which are greater 
						//than B we could break the loop beacause the other 
						//values in array are also bigger than B
		}						
		if ((i_func[i] == 0)||(i_func[i] == 1))
		{
			printf("  %f\tNot available\n", i_func[i] );
			//If Statement checks wheather the Y value is NOT available.
			//This happens only when the denominator is equal to zero. 
			//It only happens when X=1 or X=0  
		}
		else if((pow(i_func[i], 3) > 4)||(( i_func [i] > 0) && ( i_func [i] < 1)))
		{
			printf("  %f\tComplex Number\n", i_func[i] );
			//IF statement checks whether the Y value is a Complex number.
			// This is only happens when we have a square root 
			//out of negative number.It only happens when 
			//X[0,1]and X > qubic root out of four 
			
		}
		else
		{		//if our value can be found then we use next 
				//opearations to fidnd it
			out_func = (( i_func[i] + 4 ) / 
			 (sqrt(pow(i_func[i], 2) - i_func[i]))) * 
			 pow( i_func[i], 2) * 
			 sqrt(4 - pow(i_func[i], 3) );
			printf("  %f\t%f\n", i_func[i],out_func);
				//use the variable output_func just for 
				//making more clear how the values of 
				//the function is calculated
				 
				//Don't use an array for output values because 
				//I just need to find the values and print them,
		}
	} 
	return 0;
}