Question: How do I alter this code to exclude negative numbers less than 0 AND non integers such as letters and characters in the following: #include

How do I alter this code to exclude negative numbers less than 0 AND non integers such as letters and characters in the following:

#include

#include

int main ()

{

/* variable definition: */

float distance, sum;

int day;

/* Initialize */

sum = 0.0;

day = 0;

printf("This program will sum up your miles ran or walked each day this week. ");

//While Loop inputs of miles walked each day

while (day <7)

{

printf("Please enter your miles ran or walked today: ");

scanf("%f", &distance);

sum = sum + distance;

day = day + 1;

printf("On day %d, You walked or ran a total of %.02f miles in distance. ", day, distance);

}

// Output completed miles for the week as a sum

printf("Your miles completed this week is %.02f miles. Great Work! " , sum);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!