1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Len [333]
4 years ago
5

Write a program that prompts the user to input two numbers, a numerator and a divisor. Your program should then divide the numer

ator by the divisor, and display the quotient and remainder.
Computers and Technology
2 answers:
12345 [234]4 years ago
8 0
What language? JavaScript? Python?
Fed [463]4 years ago
7 0

***NOTE: <em>Since the programming language is not mentioned in the question, I am going to answer it in Python, Java, and C++, so that you have an option to choose a language of your choice.</em>***

Requirements:

1. We need to ask a user to enter two numbers, a numerator and a divisor. So obviously we need to have two variable in order to store those values.

2. We have to display the quotient and the remainder. Although we do not need to have separate variables to those, as we can display them directly inside the <em>print </em>statement (of the respective programming language), it would, however, be a good practice to save them in the variables.

Please note that there is no requirement of checking the errors, but for simplicity, I am going to add one error-check when the user enters 0 as a divisor, which is not allowed (mathematically); otherwise, it would give you an error.

Also do not forget to read the comments within the code. Each and every step is explained.

Let's code it!

<u>Python Code</u>

<em># Prompt the user to input a numerator (number)</em>

numerator = int(input("Enter a numerator: "))

<em># Prompt the user to input a divisor (number)</em>

divisor = int(input("Enter a divisor: "))

<em># Making sure that the user does not enter 0 as a divisor</em>

if divisor != 0:

<em>    # We need to divide the numerator with the divisor to get the quotient</em>

   quotient = numerator / divisor

<em>    #We need to find the remainder by using the Modulus operator</em>

   remainder = numerator % divisor

   

<em>    #Now display both the remainder and the quotient using the print statement</em>

   print("The quotient is: {}".format(int(quotient)))

   print("The remainder is: {}".format(remainder))

else:

   print("Divisor cannot be equal to 0. Please rerun the program.")

<u>Java Code</u>

<em>// First import Java Scanner module for taking inputs from the user</em>

import java.util.Scanner;

public class HelloWorld{

    public static void main(String []args){

<em>         // initialise the scanner</em>

        Scanner input = new Scanner(System. in);

<em>        // Prompt the user to input a numerator (number)</em>

       System.out.print("Enter a numerator: ");

       int numerator = input.nextInt();

<em>        // Prompt the user to input a divisor (number)</em>

        System.out.print("\nEnter a divisor: ");

       int divisor = input.nextInt();

     <em> // Making sure that the user does not enter 0 as a divisor</em>

       if (divisor == 0) {

           System.out.println("Divisor cannot be equal to 0. Please rerun the program again.");

           return;

       }

<em>        // We need to divide the numerator with the divisor to get the quotient</em>

       int quotient = numerator / divisor;

<em>        // We need to find the remainder by using the Modulus operator</em>

       int remainder = numerator % divisor;

<em>        // Now print both the remainder and the quotient using System.out.println statement</em>

       System.out.format("\nThe quotient is: %d\n", quotient);

       System.out.format("The remainder is: %d\n", remainder);

    }

}

<u>C++ Code</u>

#include <iostream>

using namespace std;

int main()

{

       int numerator = 0;

       int divisor = 0;

<em>        // Prompt the user to input a numerator (number)</em>

       cout<<"Enter a numerator: ";

       cin>>numerator;

<em>        // Prompt the user to input a divisor (number)</em>

       cout<<"Enter a divisor: ";

       cin>>divisor;

       <em>// Making sure that the user does not enter 0 as a divisor</em>

       if (divisor == 0) {

           cout<<"Divisor cannot be equal to 0. Please rerun the program again.";

           return -1;

       }

<em>        // We need to divide the numerator with the divisor to get the quotient</em>

       int quotient = numerator / divisor;

<em>        // We need to find the remainder by using the Modulus operator</em>

       int remainder = numerator % divisor;

<em>        // Now print both the remainder and the quotient using "cout" statement</em>

       cout<<"\nThe quotient is: "<<quotient<<endl;

      cout<<"The remainder is: "<<remainder<<endl;

   return 0;

}

You might be interested in
On the Audio Tools contextual tab, which tab will control how the audio file appears, if it appears, on the slide itself?
otez555 [7]

Answer:

<h2>B. Playback</h2>

Explanation:

Playback is the act of reproducing recorded sound; “he was allowed to hear the playback of his testimony”. The part of a tape recorder that reproduces the recorded material.

On the audio tools contextual tab, “playback” will control how the audio file appears, if it appears, on the slide itself.

Therefore, the correct answer is b. playback.

5 0
3 years ago
Read 2 more answers
If a disk drive has 8 surfaces and there are 1024 tracks per surface with 256 sectors per track and 512 bytes/sector. What is th
Elza [17]

Answer:

The capacity of the drive in Gigabytes equals 1.0737 Gbs

Explanation:

Given there are 1024 tracks per surface.

Number of surfaces = 8

Hence number of tracks in 8 surfaces equals 1024\times 8=8192 tracks

Now it is given that there are 256 sectors per track thus the number of sectors in 8192 tracks equals 8192\times 256=2097152 sectors

Now it is given that there are 512 bytes per sector thus the number of bytes in 2097152  equals 2097152\times 512=1073741824 bytes

Converting to gigabytes the capacity of the drive in gigabytes equals 1.0737Gbs

5 0
3 years ago
Which of the following savings vehicles usually requires a high minimum balance?
Simora [160]
? i need the following ?
8 0
3 years ago
A ____ is a copy that is kept in case values need to be restored to their original state.
Zepler [3.9K]
A backup is the copy made in this case
5 0
4 years ago
// This pseudocode is intended to display // employee net pay values. All employees have a standard // $45 deduction from their
Vikki [24]

Answer:

C++ code is given below

Explanation:

#include<iostream>

#include <cstring>

using namespace std;

int housekeeping(string EOFNAME);

int mainLoop(string name,string EOFNAME);

int finish();

void main()

{

  string name;

  string EOFNAME = "ZZZZ";

  cout << "enter the name" << endl;

  cin >> name;

  if (name != EOFNAME)

  {

      housekeeping(EOFNAME);

  }

  if (name != EOFNAME)

  {

      mainLoop(name , EOFNAME);

  }

  if (name != EOFNAME)

  {

      finish();

  }

  system("pause");

}

int housekeeping(string EOFNAME)

{  

  cout << "enter first name " << EOFNAME << " to quit " << endl;

  return 0;

}

int mainLoop(string name, string EOFNAME)

{  

  int hours;

  int rate,gross;

  int DEDUCTION = 45;

  int net;

  cout << "enter hours worked for " << name << endl;

  cin >> hours;

  cout << "enter hourly rate for " << name << endl;

  cin >> rate;

  gross = hours*rate;

  net = gross - DEDUCTION;

  if (net > 0)

  {

      cout << "net pay for " << name << " is " << net << endl;

  }

  else

  {

      cout << "dedections not covered.net is 0.";

  }

  cout << "enter next name or " << EOFNAME << " to quit" << endl;

  cin >> name;

  return 0;

}

int finish()

{

  cout << "end of job"<<endl;

  return 0;

}

3 0
4 years ago
Other questions:
  • Which if the following is an example of tangible property?
    7·1 answer
  • Match each of the following terms to its function:_________
    13·1 answer
  • _____ is the network protocol that deals with the routing of packets through interconnected networks to the final destination.
    9·1 answer
  • When it comes to safety, the choice to be safe is often up to __________?
    8·1 answer
  • If a secret key is to be used as a _________ for conventional encryption a single number must be generated.
    13·1 answer
  • Which of these are correctly formatted python dictionaries? Check all that apply.
    5·2 answers
  • A _________________________ can use SOAP headers to carry meta information in its messages. A. Web service B. REST Service C. Co
    14·1 answer
  • Andrew works for a company that develops for a company that develops optic-fiber cables for transmission of data. which layer of
    14·1 answer
  • Write a program in Cto define a structure Patient that has the following members
    12·1 answer
  • Inputting a range of numbers comprising a batch and then inputting each serially numbered document is characteristic of the cont
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!