3 Replies - 7631 Views - Last Post: 09 August 2007 - 08:30 AM Rate Topic: -----

#1 dianenacario  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-August 07

DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 12:15 AM

int[] Divide(int divisor, int dividend)
{
int remainder = dividend;
int quotient = 0;

while (remainder >= divisor)
{
remainder -= divisor;
quotient++;
}

return new int[] { quotient, remainder };
}


[b] i am trying to do a divison program..
i should not use " / or %"
i should only use a while loop or a for loop.


i wanted it to be like this,

output of program: any number / any number = quotient
input dividend: dividend
input divisor: divisor
quotient: quotient
remainder: if there is a remainder
[i]

This post has been edited by dianenacario: 09 August 2007 - 12:27 AM


Is This A Good Question/Topic? 0
  • +

Replies To: DIVIDING USING FOR LOOP AND WHILE LOOP

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 12:19 AM

Are you getting errors? If so what are they? We need more than "this don't work", how is it NOT working, what is it doing? Please provide a better explanation :)
Was This Post Helpful? 0
  • +
  • -

#3 dianenacario  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-August 07

Re: DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 12:38 AM

View Postdianenacario, on 9 Aug, 2007 - 12:15 AM, said:

int[] Divide(int divisor, int dividend)
{
int remainder = dividend;
int quotient = 0;

while (remainder >= divisor)
{
remainder -= divisor;
quotient++;
}

return new int[] { quotient, remainder };
}


[b] i am trying to do a divison program..
i should not use " / or %"
i should only use a while loop or a for loop.


i wanted it to be like this,

output of program: any number / any number = quotient
input dividend: dividend
input divisor: divisor
quotient: quotient
remainder: if there is a remainder
[i]




Im not receiving any error message but nothing appears when i start the program.
do you have any better suggestion on how i can do a division program using a for loop or while loop? im not suppose to use "/ and %"..


Im not receiving any error message but nothing appears when i start the program.
do you have any better suggestion on how i can do a division program using a for loop or while loop? im not suppose to use "/ and %"..

This post has been edited by dianenacario: 09 August 2007 - 12:40 AM

Was This Post Helpful? 0
  • +
  • -

#4 csmanoj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 06-August 07

Re: DIVIDING USING FOR LOOP AND WHILE LOOP

Posted 09 August 2007 - 08:30 AM

I put your method in my program like so...

using System;

namespace csmanoj
{
	class Division
	{
		public static void Main()
		{
			int[] answer = new int[2];
			
			answer = Divide(8, 50);
			Console.WriteLine(answer[0]+", "+answer[1]);
		}
				
		public static int[] Divide(int divisor, int dividend)
		{
			int remainder = dividend;
			int quotient = 0;
			
			while (remainder >= divisor)
			{
				remainder -= divisor;
				quotient++;
			}
			return new int[] {quotient, remainder};
		}
	}
}


And it worked. I got "6, 2" as output. I'm new to C# too so can't give you any explanation. But see if it strikes a chord for you.

This post has been edited by csmanoj: 09 August 2007 - 11:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1