im writing this code and i cant get the if else part to work, and posts that might help would be greatly appreciated
thanks
Code:
#include<stdio.h>
#include<math.h>
main()
{
#include<stdio.h>
#include<math.h>
main()
{
int x, y;
double A, B, C;
printf("Enter (double ) A, B, C:\n");
scanf("%f %f %f", A, B, C);
printf("Enter (double) x:\n");
scanf("%f", x);
{
if (x <=0)
y= (A*x*x + B);
printf("Case 1\nx value is = %d and y value is = %d", x, y);
else{
if (x <<1)
y= (B + C*x);
printf("Case 2\nx value is = %d and y value is = %d", x, y);
else{
(x >=1)
y= (B + C);
printf("Case 3\nx value is = %d and y value is = %d", x, y);
}
}
}
exit(0) ;
}
these are the errors i get:
Code:
q4.c:15: parse error before "else"
q4.c:19: parse error before "else"
q4.c: At top level:
q4.c:25: parse error before '}' token
q4.c:26: parse error before numeric constant
q4.c:26: warning: data definition has no type or storage class
this was my assignment if it helps:
Code:
/*
MAE9: Homeworki #4, Spring 2003
Due on Thursday, May 1, before 11:00 pm
A mathematical relationship between x and y is described by
the following expressions:
y= A*x^2 + B if x<=0 (Case 1)
y=B+C*x if 0<x<1 (Case 2)
y=B+C if x>=1 (Case 3)
where A, B, and C are constants. Write a C program that reads
the double values of the constants A,B,C, and the argument x
(by using scanf), and computes the corresponding value of y.
Print x and y by using %f format with 3 decimal places.
Use the pow(a,b) function to calculate x^2, and if/else
statements to choose the proper expression for y, corresponding
to selected x.
After reading A,B,C, your program should use a for loop to
evaluate y for scanned x in each of the above three cases.
Your output should look like:
Enter (double ) A, B, C:
1. 2. 3.
Enter (double) x:
0.5
Case 2
x value is = 0.500 and y value is = 3.500
Enter (double) x:
-1.
Case 1
x value is = -1.000 and y value is = 3.000
Enter (double) x:
2.
Case 3
x value is = 2.000 and y value is = 5.000
.......................................................
Note: If you started working on hw4 before Friday, and
made the output as below, it's acceptible. If you didn't,
try to get above output.
Enter (double ) A, B, C:
1. 2. 3.
Case 1
Enter (double) x:
-1.
x value is = -1.000 and y value is = 3.000
Case 2
Enter (double) x:
0.5
x value is = 0.500 and y value is = 3.500
Case 3
Enter (double) x:
2.
x value is = 2.000 and y value is = 5.000
*/
thanks for any help