0

ask Using two integers num1 and mun2
divide the first by the second
print out guotient and remainder both ints

output looks like this

First number entered
second number entered

Quotient
Remainder

Attachments
/********************************************************
*  Name:           template
*  Author:         Francis Waldron     
*  Date due:       25/09/06
*  Description:    basic C++ programming 
**********************************************************/

/***************************
*     libraries
****************************/
#include <iostream>            // needed for Cin and Cout
using namespace std;

/************************************
*     defines
*************************************/
#define  PI  3.14159

/*************************************
*     function prototype
*************************************/


/************************************
*      global variables
*************************************/

int main()
{
   float num1 = 0;
   float num2 = 0;
   int quotient = 0;
   int remainder = 0;

   quotient = num1 / num2;
   remainder = num1 % num2;
   cout << " first number entered:  ";
   cin >>num1;
   cout << " second number entered:  ";
   cin >>num2;
   if(num2 == 0)
       {
           cout << num2<< " Cannot divide by Zero";
}
   cout << "Quotient:  /n";
   cout << "Remainder:  /n";
   
   
  
     
    
     
     
     system("pause");
     return 0;
}
4
Contributors
4
Replies
5
Views
11 Years
Discussion Span
Last Post by Francis Waldron
0

The program is having many mistakes, firstly you are dividing the two numbers and then assigning them the values . So when the program encounters the statement of quotient , it will do something like 0/0. which is an error.similarly for remainder. also you are not printing the outputs . a statement like cout<<"quotient: " will print whatever is wriiten in quotes. removing quotes shall give the answer.
cout<<quotient;

0

Here's how its supposed to handle. Check it out and hope it helps

#include <iostream>
using namespace std;

int main()
{
    int num1=0;
    int num2=0;
    int quotient=0;
    int remainder=0;    

    cout << "first number entered:  ";
    cin >> num1;
    cout << "second number entered: ";
    cin >> num2;

    if (num2==0)
    {
        cout << num2 << " Cannot divide by Zero\n";
    } else
    {
        quotient  = num1 / num2;
        remainder = num1 % num2;
    
        cout << "Quotient:  " << quotient  << endl;
        cout << "Remainder: " << remainder << endl;

        //system("pause"); // you really need this??
    }
    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.