I am new to C programming. I have to write a program, that
- asks the user to enter a number, then
- performs two mathematical operations and compares the results, then
- performs another operation and outputs the end result. After that,
- it needs to ask the user whether to continue, if user answers with "y" then the program needs to start over at step (1).
Whatever I try, the program either goes into an infinite loop, or it doesn't loop at all.
Here is one of my attempts:
#include <stdlib.h>
#include <stdio.h>
void main()
{
double x;
float a, b, Y;
char z='y';
char v;
printf("My Name\n");
while (z == 'y')
{
z = 'u';
printf("Enter a number :\n");
scanf_s(" %lf", &x);
a = abs(x) / (1 - x * x);
b = 3 * x - x / (1 + x * x);
printf("a= %lf \n", a);
printf("b= %lf \n", b);
if (a <= b)
{
Y = (1 / a)*(b / 2 - 1 / 10);
}
else
{
Y = a * a + b * b * b;
}
printf("Y= %.3lf\n", Y);
printf("If you want to continue enter y :\n");
scanf_s(" %c", &z);
}
}
And here is a block diagram for the program.
How must I change the program to make it loop as required?