Tuesday, July 14, 2009

C++ I have an error that I couldn't figure out T_T?

Here is my program :





#include %26lt;stdio.h%26gt;


#include %26lt;math.h%26gt;


void drain();


int main()


{


double x, y, Y, RE;


printf("\nEnter x: ");


scanf("%lf", %26amp;x);


y = pow(exp(x), 1.5);


printf("True value of exp(1.5*%.4f) = %lf", x, y);


char ch;


fflush(stdin);


printf("\n\nEnter a character 1-4 (0 to exit):\n");


ch = getchar();


switch(ch){


case 1:


printf("1 term(s) approximation"};


Y = pow(x, 0.)/1.;


printf("Approximate exp(1.5*%.4f) = ", x);


RE = 100 * (Y - y)/y;


printf("\nRelative error = %lf", RE);


break;


default:


printf("unrecognized operator");


}


}





.c: In function `main':


:17: error: parse error before '}' token








What should i do? .... thx so much

C++ I have an error that I couldn't figure out T_T?
well, thts easy, u see, u have defined main as returning an integer but u r not returning anything


check out the same program wid the corrections below





#include %26lt;stdio.h%26gt;


#include %26lt;math.h%26gt;


void drain();


int main()


{


double x, y, Y, RE;


printf("\nEnter x: ");


scanf("%lf", %26amp;x);


y = pow(exp(x), 1.5);


printf("True value of exp(1.5*%.4f) = %lf", x, y);


char ch;


fflush(stdin);


printf("\n\nEnter a character 1-4 (0 to exit):\n");


ch = getchar();


switch(ch){


case 1:


printf("1 term(s) approximation"};


Y = pow(x, 0.)/1.;


printf("Approximate exp(1.5*%.4f) = ", x);


RE = 100 * (Y - y)/y;


printf("\nRelative error = %lf", RE);


break;


default:


printf("unrecognized operator");


}


return(0);


}





if my solution was of help, gimme the best answer vote, pls
Reply:My vote goes to this line!


printf("1 term(s) approximation"};


It is line 17!





The end character should be ) NOT }





That was fun.
Reply:switch(ch) { %26lt;!-- put a space between (ch) and {


case 1:


printf("1 term(s) approximation"};


Y = pow(x, 0.)/1.; %26lt;!-- why do u have a point (.) after 1? if its a decimal put 1.0 and why do u havea period after 0?


printf("Approximate exp(1.5*%.4f) = ", x);


RE = 100 * (Y - y)/y;


printf("\nRelative error = %lf", RE);


break;


default:


printf("unrecognized operator");


No comments:

Post a Comment