This is what I've got so far:
#include <iomanip>
#include <cmath>
#include <fstream>
#include<string>
#include<iostream>
using namespace std;
int main()
{
double numA=0;
double numB=0;
double productB;
double accumulator = 0;
cout<<"Your two numbers to multiply are?"<<endl;
cin>>numA>>numB;
double productA = (numA * numB);
if (numA>numB||numA%2==1)//check if larger and odd???
{
accumulator+=accumulator;//how to add the smallest # to the accumulator???
}
then (numA/2) + (2*numB);//something to make the program continue
{
accumulator+=accumulator;//if the larger number's
division is odd, the smaller number's doubling is added to an accumulator
}//after all this assign the value to productB
Any assistance is appreciated.
cout<<numA<<" times "<<numB<<" by conventional math = "<<productA<<endl;
cout<<numA<<" times "<<numB<<" by Brown's method = "<<productB<<endl;
return 0;
}
The assignment is as follows:
Program "multiplication"
With too much time on his hands, Professor Brown has devised a new system of multiplication
called the "half and double" method. Two numbers are entered in from the keyboard. If the
larger number is odd, the smaller number is added to an accumulator. Then the larger number
is integer divided by two and the smaller number is doubled. Again if the larger number's
division is odd, the smaller number's doubling is added to an accumulator. lf the larger number
is even, nothing is added to the accumulator. This is repeated until the large number
sequence equals zero. The accumulator now holds the multiplication answer.
Write a program using functions, that will accomplish this task. Repeat until the user wishes to stop.
lt is not necessary to display the accumulation work as shown in the examples.
Output is to the screen and printer and should look like:
Your Name Class # Date & Time
XXXX times XXXX by conventional math = XXXXXXX
XXXX times XXXX by Zoo's method = XXXXXXX
Example 1) 75 x 23 = 1725
Larger Smaller Add to Accumulator
75 23 23
37 46 46
18 92 O
9 184 184
4 368 O
2 736 O
1 1472 1472
1725(TOTAL & PRODUCT)
Example 2)
122 x 251 = 30622
Larger Smaller Add to Accumulator
251 122 122
125 244 244
62 488 O
31 976 976
15 1952 1952
7 3904 3904
3 7808 7808
1 15616 15616
30622(TOTAL & PRODUCT)
Run the program three times with the following:
1. 82 x 122 (Entered in that order) 2. 124 x 463 (Entered in that order)
3. 1219 x 1641 (Entered in that order)