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

  • Thread starter thatspreets
  • Start date
  • Tags
    Computer
In summary, the conversation is about someone asking for help to write a program to perform integer division in either Turbo Pascal or C++. The program should take in two numbers from the user, the dividend and divisor, and return the quotient and remainder. The user must also provide any other necessary numbers. The conversation includes a sample code in Turbo Pascal and a suggestion for using the modulus operator in C++.
  • #1
thatspreets
1
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
  • #2
Well depends what Langauge 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.
 
  • #3
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
 

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

1. What is a Little Man Computer (LMC)?

The Little Man Computer (LMC) is a simplified computer architecture designed to help beginners understand the basic concepts of computer programming. It consists of a CPU, memory, and input/output components, and operates on a simple instruction set.

2. What is the purpose of the LMC?

The purpose of the LMC is to introduce individuals to the fundamentals of computer programming, such as data manipulation, conditional statements, and loops. It is commonly used as a teaching tool in computer science courses.

3. How do I program the LMC?

Programming the LMC involves writing instructions in the form of three-digit numbers, also known as opcodes, and storing them in the LMC's memory. These instructions can then be executed by the LMC's CPU, allowing the user to perform calculations and manipulate data.

4. What are some common LMC instructions?

Some common LMC instructions include ADD (addition), SUB (subtraction), STA (store), LDA (load), and BRZ (branch if zero). These instructions allow the user to perform basic arithmetic operations, store and retrieve data, and control the flow of the program.

5. Where can I find resources for learning LMC?

There are many online tutorials and resources available for learning the LMC, including interactive simulators, coding challenges, and video tutorials. You can also find textbooks and other educational materials on the LMC in libraries or online bookstores.

Similar threads

Replies
5
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
14
Views
31K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
3
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
29
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
17
Views
4K
Back
Top