assignment27 - { if(divisor != 0) { double divisionAnswer;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Write a program that prompts the user for two  numbers  the dividend and the divisor  and   then displays the division of the dividend by  the divisor. Your function must be called   displayDivision and will check that the divisor  is not zero before attempting the division. If   the divisor is zero, your function will display   the error message shown below. Your program will  then ask the user if s/he wants to continue. If  the user enters a 'y' (either upper or lower case),  continue to ask the user for the next dividend and   divisor. Use the screen shot below as a guide.  */  #include <iostream>  #include <string>  #include <cmath>  using namespace std;   double displayDivision(double dividend, double divisor)  
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { if(divisor != 0) { double divisionAnswer; divisionAnswer = dividend/divisor; cout &lt;&lt; divisionAnswer &lt;&lt; endl; return divisionAnswer; } else { cout &lt;&lt; &quot;Error: Attempt to divide by zero!&quot; &lt;&lt; endl; return 0; } } int main() { char qAnswer = 'y'; do { double dividend, divisor; cout &lt;&lt; &quot;Enter the dividend: &quot;; cin &gt;&gt; dividend; cout &lt;&lt; &quot;Enter the divisor: &quot;; cin &gt;&gt; divisor; displayDivision(dividend, divisor); cout &lt;&lt; &quot;Do you want to continue (y/n)? &quot;; cin &gt;&gt; qAnswer; } while (qAnswer == 'y'); }...
View Full Document

Page1 / 2

assignment27 - { if(divisor != 0) { double divisionAnswer;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online