Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
6/20/2006 5:20:28 PM EDT
I'm trying to write a C++ program that will graphically display the actual steps of longhand division, just like you would write it on paper. I dont even know where to begin, except for the actual calculation. Here's the code I have so far:

#include <iostream>
#include <iomanip>
using namespace std;
int main()

{
//declare variables

int first;
int second;
int quotient;
int remainder;
//input for variables

cout << "\nThis program will perform long division with two numbers." << endl;
cout << "\nPlease enter the first number." << endl;
cin >> first;
cout << "\nNow enter the second number." << endl;
cin >> second;
while (second == 0)
{
cout << "\nPlease enter a number other than zero. " << endl;
cin >> second;
}
quotient = first / second;
remainder = first % second;

cout << endl << second << ")" << first << " = " << quotient << " R" << remainder << endl;


return 0;
}
6/20/2006 5:24:45 PM EDT
[#1]
Still doing C, with more Java thrown in, sorry.  
6/20/2006 5:31:15 PM EDT
[#2]

Quoted:
Still doing C, with more Java thrown in, sorry.  


This is linear logic so there is no difference between C, C++, Java, or Lisp save syntax.

eta: gimme a few minutes.
6/20/2006 5:32:23 PM EDT
[#3]
So where are you having trouble?

This is homework, isn't it?  Only COMP SCI professors are dumb enough to require stuff like this to be written in C++.

Or maybe I'm just bitter that they gave me Fs for submitting my work in K&R C.
6/20/2006 5:35:17 PM EDT
[#4]

Quoted:

Quoted:
Still doing C, with more Java thrown in, sorry.  


This is linear logic so there is no difference between C, C++, Java, or Lisp save syntax.

eta: gimme a few minutes.



He is asking how to graphically display, I assume like Mathmatica or Mathcad or something...
6/20/2006 5:39:47 PM EDT
[#5]
I would suggest actually doing a longhand division problem by hand. Do some with remainders and with numbers with different orders of magnitude.

Then from that you can get an idea for your algorithim. Its going to require subtraction and integer division.

You will need some code to do the input and some code to do the formatting of your outputs.



6/20/2006 5:41:12 PM EDT
[#6]
We are not going to do your homework.
6/20/2006 5:41:47 PM EDT
[#7]
Simple. Write down every longhand division problem possible, scan them all, and display pictures as needed.




6/20/2006 5:42:51 PM EDT
[#8]

Quoted:
Simple. Write down every longhand division problem possible, scan them all, and display pictures as needed.







Now this man is a straight shooter destined for upper middle-level management.
6/20/2006 5:43:25 PM EDT
[#9]

Quoted:

Quoted:

Quoted:
Still doing C, with more Java thrown in, sorry.  


This is linear logic so there is no difference between C, C++, Java, or Lisp save syntax.

eta: gimme a few minutes.



He is asking how to graphically display, I assume like Mathmatica or Mathcad or something...


No, I understood him to mean that the program would do this:


4 / 60

4 / 6 = 1
1 * 4 = 4
60 - 40 = 20
4 / 20 = 5

Answer = 15



eta: Thank christ I am no longer in college.
6/20/2006 5:44:02 PM EDT
[#10]

Quoted:
So where are you having trouble?

This is homework, isn't it?  Only COMP SCI professors are dumb enough to require stuff like this to be written in C++.

Or maybe I'm just bitter that they gave me Fs for submitting my work in K&R C.



Yep this is a stupid COMP SCI homework problem. I'm having trouble coming up with the logic on how to calculate and display the problem like you would write it on paper.

Ex:

   
6)500 = 83R2
 -48
-------
    20
  - 18
-------
       2

 
 
6/20/2006 5:44:32 PM EDT
[#11]
But the dumb prof wants it shown.. he wants to see -> "ok.. well, 4 won't go into 3, so throw on a decimal and put a zero after the 3, then see how many times 4 will fit.."?


This is why we have computers for in the FIRST place!  To CAWM-PEWT things.


Edit: Use bit-shifting!
6/20/2006 5:46:26 PM EDT
[#12]
Well I'm not going to write it for you but essentially you need to perform a division, keep the quotient and display it as the first digit.  Then take the remainder (using modulo operator) and multiply it by 10.  Then redivide and keep looping this until you reach a predetermined decimal place or the remainder is 0.
6/20/2006 5:48:04 PM EDT
[#13]

Quoted:
But the dumb prof wants it shown.. he wants to see -> "ok.. well, 4 won't go into 3, so throw on a decimal and put a zero after the 3, then see how many times 4 will fit.."?


This is why we have computers for in the FIRST place!  To CAWM-PEWT things.



Yep, thats what the prof wants. Can't come up with the logic.
6/20/2006 5:49:47 PM EDT
[#14]

Quoted:

Quoted:
But the dumb prof wants it shown.. he wants to see -> "ok.. well, 4 won't go into 3, so throw on a decimal and put a zero after the 3, then see how many times 4 will fit.."?


This is why we have computers for in the FIRST place!  To CAWM-PEWT things.



Yep, thats what the prof wants. Can't come up with the logic.



Tell him the Internet thinks he is a fucking moron.
6/20/2006 5:50:00 PM EDT
[#15]

Quoted:
Well I'm not going to write it for you but essentially you need to perform a division, keep the quotient and display it as the first digit.  Then take the remainder (using modulo operator) and multiply it by 10.  Then redivide and keep looping this until you reach a predetermined decimal place or the remainder is 0.



Thanks, big help.