Thread: Create a program that evaluate an equation?

1. Create a program that evaluate an equation?

Hi! I just started to learn C program and I ran into this little problem.

This is the assignment:

Write the C program that evaluates the value of y=pow(c,1+x), for x in the
interval: a<x<=b. Scan double values of a and b>a. Scan a double value c>0.
Then, scan x and evaluate y and y/x. If x is not from the required interval a<x<=b,
scan it again, shown in the output below. If you don't scan it correctly twice in a row,
exit the program (as shown in the output below). To exit, use the function exit(0), but
don't forget to include stdlib.h above the main.

Your output should look like:

Code:
```Enter a and b>a:
0.5 2.75
Enter c>0:
1.5
enter a double a<x<=b:
0.25
The x value is = 0.250000
You didn't enter x from a<x<=b!
Enter x from a<x<=b:
2.5
The y value is = 4.133514
The y/x value is = 1.653406```
......

On the other hand, if you don't enter proper x twice in a row, you output
should look like:
Code:
```Enter a and b>a:
0.5 2.75
Enter c>0:
1.5
enter a double a<x<=b:
0.25
The x value is = 0.250000
You didn't enter x from a<x<=b!
Enter x from a<x<=b:
3.1
You didn't enter x from a<x<=b! Exit!```
----------------------------------------------------

This is what I attempted so far:
Code:
```#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int num1, num2, num3, num4;

printf("Enter a and b>a:");
scanf("%lf %lf",num1, num2);
printf("Enter c>0:");
scanf("%lf",num3);
printf("Enter a double a<x<=b:");
scanf("%lf",num4);
return 0;
}```
I am kind of lost right now. Could you guys give out some adivice or hints how to do this. Thank you!

2. Sure, my advice is that you missed some classes and you shouldn't do that. I suggest you review your book on loops, and maybe learn something about the math lib. For loops look at:Lesson 3: Loops in the board's C Made Easy Series. As for the math lib, I think you can find that all by yourself.

Popular pages Recent additions