1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
int
main(void)
{
/********************* DECLARATION OF VARIABLES **************************/
double param, result, radians, sinx;
char ans= 'y', unit, sum, dummy;
/*******************THE EXECUTABLE PART OF THE PROGRAM ********************/
/******* Print the Opening Message *******/
msg1();
/******* Computations ******/
while (ans == 'y'|| ans == 'Y')
{
printf ("\n\n What number do you want to use?\n\n");
scanf ("%lf%c", ¶m, &dummy); //<--- you forgot the %c to read the enter character
result= sin(param*PI/180);
printf ("The sin of %lf is %lf\n", param, result); //<--- Do not give addresses of param and result to printf (with & operator)
printf("\n\n Would you like to enter another number? (Y for yes)\n\n");
scanf("%c", &ans);
}
//Removed if statement
printf ("\n\n Thank you for using me to figure sine \n\n");
scanf("%c", &ans); //<--- see explanation below (*)
return 0;
}
/***************************************************************************/
|
(*) i have to repeat myself, if you write %c in the scanf string, it means you want to read a char (character). If you write %lf, it means you want to read a double value from input. So if you write
scanf("%c", ¶m, &dummy);
it means that you read a character (%c) and store it in the first parameter provided to the function after the string literal "%c", which is param. But param is a variable of type double. Assigning a char to it makes no sense. Furthermore there is another parameter, namely
&dummy
. You did not specify any more than "%c" to read from standart input, so this parameter is redundant. Nothing is read from input and copied to the dummy variable.
To summarize this, the first parameter is
¶m
, which is the address of a double variable and the second parameter is
&dummy
, which is the address of a char variable, so the correct string would be
"%lf%c"
, or the whole line
scanf("%lf%c",¶m,&dummy);
.
But at this place in your sourcecode this logically makes no sense, because all you want is the user to press enter to exit the program, so it would be most useful to write something like
scanf("%c", &dummy)
or
scanf("%c", &ans)
. (Doesn't matter if you use dummy or ans since the program is about to exit anyway and you're not going to use the value anymore)