3 Replies - 228 Views - Last Post: 02 September 2013 - 02:14 PM Rate Topic: -----

#1 Tyrion101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 23-August 13

Why do I keep getting the factors printed backwards?

Posted 02 September 2013 - 01:27 PM

When I run this program it divides from say, 1-9, or whatever the second number is entered. I was wondering if it is possible to change it to display 9-1 instead?

#include <iostream>
using namespace std;

//This program will factor numbers
//with user decided numbers

int main()
{
	double a, b, result;
	a = 0;
	b = 0;
	
	cout << "Enter a number: ";
	cin >> a;

	cout << "Enter a second number: ";
	cin >> b;

	while (result = a/b, b > 0)
	{
		b--;
		cout << result << endl;
	}
	
	system("pause");
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Why do I keep getting the factors printed backwards?

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4133
  • View blog
  • Posts: 12,866
  • Joined: 25-December 09

Re: Why do I keep getting the factors printed backwards?

Posted 02 September 2013 - 01:30 PM

Can you please tell me in English what the following code should be doing?
    while (result = a/b, b > 0)




Jim
Was This Post Helpful? 0
  • +
  • -

#3 Tyrion101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 23-August 13

Re: Why do I keep getting the factors printed backwards?

Posted 02 September 2013 - 01:46 PM

Well, you put in number a, say, 120, then number b, say 12, it runs a loop from 120/1,120/2,120/3 etc etc, and I was just wondering if I could reverse the display order, I want it to display from 120/12 120/11 120/10 etc.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4133
  • View blog
  • Posts: 12,866
  • Joined: 25-December 09

Re: Why do I keep getting the factors printed backwards?

Posted 02 September 2013 - 02:14 PM

For what you're trying to do I recommend you look into using the for() loop.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1