Tuesday
May 21, 2013

Homework Help: C Programming

Posted by gnozahs on Wednesday, September 30, 2009 at 5:48pm.

How do you reprompt after the user inputs a wrong number into the program in C Programming? Loop structure?

i.e.
I want my code to do this:

Enter a Compass Heading: 500.7
Please Input a Compass Heading between 0 and 360 Degrees.
Enter a Compass Heading: 360.0

If the user puts a number not in 0 - 360, I want the program to reprompt or start over again.

And where would I put the loop code in?
CODE:
/* Directives */

#include <stdio.h>

int main(void)
{

double heading; /*compass heading in degrees*/

/* Get compass heading */
printf("Enter a Compass Heading: ");
scanf("%lf", &heading);

/* Display equivalent compass bearing */
if (heading < 0.0)
printf("Please Input a Compass Heading between 0 and 360 Degrees.\n", heading);

else if(heading < 90.0)
printf("Compass Bearing: North %.1f Deg East\n", heading);

else if(heading <= 180.0)
printf("Compass Bearing: South %.1f Deg East\n", 180 - heading);

else if(heading <= 270.0)
printf("Compass Bearing: South %.1f Deg West\n", heading - 180.0);

else if(heading <360.0)
printf("Compass Bearing: North %.1f Deg West\n", 360.0 - heading);

else
printf("Please Input a Compass Heading between 0 and 360 Degrees.\n", heading);

/* End Program */
return(0);
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Programming in c++ - Write a program in c++ that inputs a number [1-12] from the...
Programming - Write a pseudocode program that asks the user for an integer ...
programming - Using Raptor, create a condition loop that will ask the user for ...
programming - 1. Develop a menu-driven program that inputs two numbers and, at ...
Programming - Write a program that inputs (from the user) the number of hours ...
computer Programming - A small startup software developer company needs to ...
Oop programming - Write a program that inputs (from the user) the number of ...
programming - creat a logic for a program that continuously prompts the user for...
computer programming - : Create a program like KBC game show where program ask ...
Computer programming - Sorting is a common operation used in programming. ...

For Further Reading

Search
Members
Community