March 28, 2015

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 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?
/* 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);

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

/* End Program */

Answer this Question

First Name:
School Subject:

Related Questions

programming - Write a program which allows user to enter 10 student names and ...
Programming in c++ - Write a program in c++ that inputs a number [1-12] from the...
programming - Using Raptor, create a condition loop that will ask the user for ...
Computer Literary - Which of the following is Not an example of debugging A)...
C programming - A few questions, all involving "for" loops that I am unsure how ...
programming - Write a C++ code to count the number of characters, words, and ...
C Programming - Write a program that prompts the user to enter a temperature, ...
Programming - Write a pseudocode program that asks the user for an integer ...
Programming logic and design - Design a program that lets the user enter the ...
Applied Programming - APPLIED PROGRAMMING (APR520S) ASSIGNMENT 1 Problem Solving...