Please only offer helpful suggestions. I'm confused - when you run the program, the 2 and 5 are printed to the top of the screen automatically? Or did you enter them, or?
cscgal
The Queen of DaniWeb
19,424 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Ah, yes, scanf . Trouble is almost guaranteed until you decide to quit using it.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
One of the recommendations, if you followed the link I previously posted, was to use fgets and sscanf. For example,
#include <stdio.h>
#include <math.h>
int main(void)
{
double a, b, c;
char buffer [ BUFSIZ ];
puts("CAN YOU FEEL THE POWER???\n"
"Just enter 2 variables (a and b respectively)\n"
"This program will calculate a^b and return the result.\n"
"Enter your to variables below:");
fflush(stdout);
if ( fgets(buffer, sizeof buffer, stdin) )
{
if ( sscanf(buffer, "%lf%lf", &a, &b) == 2 )
{
c = pow(a, b);
printf("%g ^ %g = %g\n", a, b, c);
}
}
return 0;
}
/* mu output
CAN YOU FEEL THE POWER???
Just enter 2 variables (a and b respectively)
This program will calculate a^b and return the result.
Enter your to variables below:
5 4
5 ^ 4 = 625
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314