- Joined
- Apr 13, 2011
- Messages
- 3
- Reaction score
- 0
Hello every one
I faced a small problem while studying c++
I hope you can help me with it
my problem is
when I implement this code :
and I run the program
the program skips the second scanf :bored: ..
as a solution
I learned that I have to use fflush(stdin) between the two scanf's ..
..
ok , so what about this code .. ?
it's almost the same code as the first program .. but it never skips the second scanf !!
can anybody help me ..
..
to be clear ,my questions are :
1.where is the problem in the first program when the second program which is almost the same don't have any problem in it .. ?!
2.when and where should I use scanf and should I use fflush(stdin) between scanf's or not ?
best regards and thanks in advance
I faced a small problem while studying c++
I hope you can help me with it
my problem is
when I implement this code :
Code:
#include <stdio.h>
#include <math.h>
int main(void) {
double h , x ,z;
printf("Enter h :");
scanf("%lf",&h );
printf("Enter x : " );
scanf("&lf",&x );
z= x + h ;
printf(" z= " , z );
return 0;
}
and I run the program
the program skips the second scanf :bored: ..
as a solution
I learned that I have to use fflush(stdin) between the two scanf's ..
..
ok , so what about this code .. ?
Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159
int main() {
double side1, side2,side3,angle;
printf("Enter side1 (cm): ");
scanf("%lf",&side1);
printf("Enter side2 (cm): ");
scanf("%lf",&side2);
printf("Enter angle in radians: ");
scanf("%lf",&angle);
side3 = sqrt(side1*side1+side2*side2-2*side1*side2*cos(angle));
printf("side3 = %.2f cm\n",side3);
return 0;
}
it's almost the same code as the first program .. but it never skips the second scanf !!
can anybody help me ..
..
to be clear ,my questions are :
1.where is the problem in the first program when the second program which is almost the same don't have any problem in it .. ?!
2.when and where should I use scanf and should I use fflush(stdin) between scanf's or not ?
best regards and thanks in advance
Last edited: