Help writing a C++ program for integer division with user input

  • Context: C/C++ 
  • Thread starter Thread starter thatspreets
  • Start date Start date
  • Tags Tags
    Computer
Click For Summary
SUMMARY

The discussion focuses on writing a C++ program for performing integer division based on user input. The program requires users to input a dividend and a divisor, then calculates and returns the quotient and remainder using the integer division and modulus operations. Key code snippets are provided, illustrating the implementation in both Turbo Pascal and C++. The C++ implementation specifically utilizes the integer division operator and the modulus operator for accurate calculations.

PREREQUISITES
  • Understanding of C++ syntax and structure
  • Familiarity with integer division and modulus operations
  • Basic knowledge of user input handling in C++
  • Experience with programming logic and flow control
NEXT STEPS
  • Explore C++ input/output functions for enhanced user interaction
  • Learn about error handling in C++ to manage invalid user inputs
  • Investigate the use of functions in C++ for modular programming
  • Study advanced C++ concepts such as exception handling for robust applications
USEFUL FOR

Beginner to intermediate C++ programmers, educators teaching programming concepts, and anyone interested in implementing basic arithmetic operations in C++.

thatspreets
Messages
1
Reaction score
0
little man computer...help pleasezz...urgent

can some1 pl help me write a program to perform the integer division of two numbers (dividend=divisor*quotient+remander). DIvidend and Divisor should be provided by the user, and the quotient and the remainder should be returned to the user. the user must also supply any numbers that may be required.


thanxx in advance
 
Technology news on Phys.org
Well depends what language you're Writing in.

If it was Turbo pascal.
program div;
uses crt;
var
a:Integer;
b:integer;
c:integer;
begin

writeln ("Division of 2 numbers");
repeat
write (' Enter 2 numbers to divide by :');
read(a,b);
until (a,b<>0);
C:=a/b;
Writeln (' Division of ',a,' by ',b,' := ,'c);
readln;

end;

Btw ..I haven't wrote pascal in 2 years sooo...not Snippet proof.
 
if it is in c++ you would do something like
int dividend;//given by the user somehow
int divisor;//given by the user somehow
int quotient = dividend/divisor;//performs integer division you'll get the right number
int remainder = dividend%divisor;//Modulus operator, gives you the remainder
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
35K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 17 ·
Replies
17
Views
5K
Replies
3
Views
2K
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 18 ·
Replies
18
Views
8K