Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m using C... I want my user to be able to input real numbers like 2.5 forthe

ID: 3609654 • Letter: I

Question

I'm using C... I want my user to be able to input real numbers like 2.5 forthe wave height, so I set my variable as a double. The programcompiles. I don't know why, but I don't enter my while loop whenthe user enters 0.0 or negative numbers. Here is my code... #include <stdio.h>
#include <stdlib.h>
#include<math.h>
doubleheightfwave=0; printf("enter a real number forthe first wave height: ");
scanf(" %f", &heightfwave);
while (heightfwave <= 0)
    {
        printf("That is invalid.Please enter a real number greater than zero for thefirst wave height: ");
        scanf("%f",&heightfwave);
    } Any help would be greatly appreciated. Please don't laugh,this is my first programming class. ;) I'm using C... I want my user to be able to input real numbers like 2.5 forthe wave height, so I set my variable as a double. The programcompiles. I don't know why, but I don't enter my while loop whenthe user enters 0.0 or negative numbers. Here is my code... #include <stdio.h>
#include <stdlib.h>
#include<math.h>
doubleheightfwave=0; printf("enter a real number forthe first wave height: ");
scanf(" %f", &heightfwave);
while (heightfwave <= 0)
    {
        printf("That is invalid.Please enter a real number greater than zero for thefirst wave height: ");
        scanf("%f",&heightfwave);
    } Any help would be greatly appreciated. Please don't laugh,this is my first programming class. ;)

Explanation / Answer


//Dear, u have used the %f ...fordouble value %lf is used. //Hope this will helpyou.. //Don't forget to rateit.


#include <stdio.h> #include <stdlib.h> #include<math.h> int main(){    double heightfwave=0; printf("enter a real number for the first wave height:"); scanf("%lf",&heightfwave);   while (heightfwave <= 0)    {    printf("That is invalid.Please enter a real number greater than zero for the first waveheight: ");    scanf("%lf", &heightfwave);    }    system("pause"); }