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
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
/********************************************************
* 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;
}
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;
if a and b are integers.....
quotient = a / b;
remainder = a % b;
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;
}
thanks for all your help . Everything work great now.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.