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

In this project you will begin to explore the basics of input and output from a

ID: 3884360 • Letter: I

Question

In this project you will begin to explore the basics of input and output from a C program. In order to perform error checking and to provide a robust, interactive program, you will also get to grips with looping and conditionals. Additionally, you will get some practice using Makefiles and the compiler. Submission Instructions This and all other assignments will be submitted through BBLearn. Look for the submission link in the same place you found this assignment. Submit all your .c and .h files along with your Makefile, but do not zip them! Technical Description and Instructions Your program will take some inputs from the user and use them to perform a ballistic calculation, that is, it will calculate how long it would take for a launched object to hit the ground and how far the launched object went. Specifically, it will prompt the user for a starting height above the ground for the object, the angle of launch, and the initial launch velocity. Once good inputs have been collected, your program will then display the time and distance results to the user. Note that your program may be evaluated by a program I compose for just this purpose. As such, when the instructions indicate that something should be printed in a certain way, failing to do so may cause my evaluator to reject your program! Your program should do the following: Display a welcome message. Prompt for a height above the ground in meters. Your program should accept numbers with decimal parts such as 16.037 for this input. Any number less than 0 should be rejected with this message "Input Error: Unable to accept negative starting height". Likewise, if the user enters something that is not a number, it should be rejected with "Input Error: Expected a positive number". All error messages should end with at least one newline ( ). If you reject an input, reprint the initial prompt and wait for input again. After receiving acceptable input for the height, prompt the user for a launching angle. The angle given will be in degrees and should be between 90^and -90^If an invalid angle is entered, reject it with the message "Input Error: Expected an angle between 90 and -90". Like the previous item, reprompt for input until a correct input is received.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){

    float height;
    float angle;
    char inp[20];
    int valid = 0;
    do {
      printf("Enter height : ");
      scanf("%s",inp);
      height = atof(inp);
     
      if (height == 0.00){
          printf("Input Error:Expected a positive number ");
      }
      else if (height < 0){
          printf("Input Error:Unable to accept negative starting height ");
      }
      else{
          valid = 1;
          printf("Input success: Height : %0.2f ",height);
      }
   
    } while (valid == 0);
    valid = 0;
    do {
      printf("Enter launching angle : ");
      scanf("%s",inp);
      angle = atof(inp);
      if (angle == 0.0){
          printf("Input Error:Expected a positive number ");
      }
      else if (angle < -90 || angle > 90){
          printf("Input Error:out of range ");
      }
      else{
          valid = 1;
          printf("Input success: Launching Angle : %0.2f ",angle);
      }
   
    } while (valid == 0);

    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote