In This Code, Shown Below, Find The String W/c Satisfies The Problem...
Printable View
In This Code, Shown Below, Find The String W/c Satisfies The Problem...
Code:#include <iostream.h>
#include <conio.h>
int main()
{
int x;
int y;
int product = 0;
cout<<"input first number:";
cin>>x;
cout<<"input second number:";
cin>>y;
for(int i=0; i<x; i++)
{
product +=y;
}
cout<<"Product is:"<<product;
getch();
return 0;
}
#include <iostream>
remove conio.h
and replace getch by something portable (see FAQ)
your program calculates x*y using addiction.
So what is the problem? you want to replace addiction with substraction to calculate x/y? Or what?
using subtraction to calculate x/y
so show the code that USES substruction, and describe your problem with itQuote:
Originally Posted by blacksnake
the problem looking for is input two numbers and compute for division using subtraction operator...
It is not a problem - just assignment description. Show your code you have a problem withQuote:
Originally Posted by blacksnake
Is there a problem with this code?Code:#include <iostream.h>
int main()
{
int x;
int y;
int rem;
int quotient = 0;
cout<<"input first number:";
cin>>x;
cout<<"input second number:";
cin>>y;
for(int i=0; i<y; i--)
{
quotient -=x;
}
cout<<"Quotient is:"<<quotient<<"Remainder is:"<<rem;
return 0;
}
could you explain your algorithm? in English?
process:
1. Input two numbers
2. compute for division but using subtraction operator...just like multiplication using addition
3. compute for the remainder(rem=x/y)
example for process#2 :
100/10=10
100-10-10-10-10-10-10-10-10-10-10=0
@Vart
A little off topic, but does that mean somthing to do with the ladies? You "grab a spoon" or somthing of that context? Lol., sorry but Im intersted in the quote.Quote:
there is no spoon
MatrixQuote:
Originally Posted by swgh
lift (before freeing Morpheus)
Neo looks up:
- There is no spoon, - and shouts the cabin down going with Trinity up.
So you shouldQuote:
Originally Posted by blacksnake
count number of substructions before y goes to 0.
you don't know it in the beginning
when finished counter contains a result, y - reminder of divisionCode:1. counter = 0
2. if (y > x) {y-=x; counter++}
3. goto 2
Now write it in more details, and then - write a code that does it
I think I took it as the wrong verison of the meaning then. Thanks Vart.
it is a little bit confused, is it possible to use for loop to satisfy the equation?Quote:
Originally Posted by vart