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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started