Question

In: Computer Science

A program written in C that asks for the distance to be entered and then prints...

A program written in C that asks for the distance to be entered and then prints the fare

A transportation company has the following rates

  1. For the first 100 miles                                                       20 cents a mile
  2. For the next 100 miles                                                       a) + 10 cents per mile over 100 miles
  3. For the next 100 miles                                                       b) + 8 cents per mile over 200 miles
  4. more than 300 miles                                                          c) + 5 cents per mile over 300 miles

Write a program that asks for the distance to be entered and then prints the fare

Check your answers       50 miles should cost    $10
150 miles should cost    $25
300 miles should cost    $38

Solutions

Expert Solution

CODE :

OUTPUT :

Raw_Code :

#include<stdio.h>           //including standard library
int main(){
   int miles;
   float cents,dollors;       //declaring required variables
   printf("Enter Number of Miles : ");      
   scanf("%d",&miles);               //taking miles as input
   if(miles<=100){                   //if it is first 100 miles
       cents = miles * 20;
   }
   else if(miles > 100 && miles <= 200){       //if it is less than 200 miles
       cents = (100 * 20) + ((miles - 100) * 10);
   }
   else if(miles > 200 && miles <= 300){           //if it is less than 300 miles
       cents = (100 * 20) + (100 * 10) + ((miles - 200) * 8);
   }
   else if(miles > 300){           //if it is greater than 300 miles
       cents = (100 * 20) + (100 * 10) + (100 * 8) + ((miles - 300) * 5);
   }
   dollors = cents / 100;           //converting cents to dollors
   printf("The Transport Fare for %d miles is : $%.2f\n",miles,dollors);       //printing required output
   return 0;
}

**********Comment me for any Queries and Rate me up*************


Related Solutions

Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Write a short program that asks the user for a sentence and prints the result of...
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
Tail of a File, C++ Program. write a program that asks the user for the name...
Tail of a File, C++ Program. write a program that asks the user for the name of a text file. The program should display the last 10 lines, or all lines if less than 10. The program should do this using seekg Here is what I have so far. #include<iostream> #include<fstream> #include<string> using namespace std; class File { private:    fstream file;    string name; public:    int countlines();    void printlines(); }; int File::countlines() {    int total =...
Write a C++ program that prints the insurance fee to pay for apet according to...
Write a C++ program that prints the insurance fee to pay for a pet according to the following rules:(NOTE:You must use a switch statement to determine pet fee.)A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been spayedcosts $40.A cat that has not been spayedcosts $60.A bird or reptile costs nothing.Any other animal generates an error message.The program should prompt the user for the appropriate information: a character code for...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT