Infinite Loop </3

Hi guys. Can you help me? I'm kinda bummed. Tf. Keeps on doing infinite loops. Thanks :)

//Write a program that will ask for 3 numbers from the user.Amongst the
//three(3) values, determine the smallest,middle,and biggest number.The
//smallest and the biggest numbers serve as the range and the middle
//number serves as the multiple. Display the multiples of the given
//range. The program should repeat until the user exits.

#include <iostream>
using namespace std;

int main () {

int num1;
int num2;
int num3;
int smallest;
int middle;
int biggest;
int multiple;
char ans='Y';

//Type the first three numbers.
cout << "Type 3 numbers: " ;
cin >> num1 >> num2 >> num3;

if (num1 < num2 && num1 < num3) {
smallest = num1;
middle = num2;
biggest = num3;
}
else
if (num2 < num1 && num2 < num3) {
smallest = num2;
middle = num1;
biggest = num3;
}
else
if (num3 < num1 && num3 < num2) {
smallest = num3;
middle = num1;
biggest = num2;
}

//Display the multiples of the given number.
cout << "Multiples of " << num1 << " from " << num2 << " to " << num3 << ": ";
while (smallest<biggest || smallest<=middle)
cout << smallest++ << " ";

return 0;
}
closed account (E0p9LyTq)
Maybe it is the numbers you are inputting? I didn't run into an infinite loop:

Type 3 numbers: 12 5 25
Multiples of 12 from 5 to 25: 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2
3 24
Well, the way you tried finding the biggest, middle and smallest was completely wrong. You didn't achieve anything. This is something you could've done:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while (true)
	{
		int num1, num2, num3;
		cout << "First number: ";
		cin >> num1;
		cout << "Second number: ";
		cin >> num2;
		cout << "Third number: ";
		cin >> num3;

		int biggest = max(num1, max(num2, num3));
		int smallest = min(num1, min(num2, num3));
		int middle;

		if (num1 != biggest && num1 != smallest) { middle = num1; }
		if (num2 != biggest && num2 != smallest) { middle = num2; }
		if (num3 != biggest && num3 != smallest) { middle = num3; }

		cout << "\nMultiples of " << middle << " in the range [" << smallest << ", " << biggest << "]:\n";
		for (int i = smallest; i < biggest; i++)
		{
			cout << middle << "*" << i << "=" << middle * i << endl;
		}
		cout << endl;
	}

	cin.ignore();
	cin.get();
	return 0;
}


**My mathematics don't go as far as English lol So I hope this is how you find the "multiples" of a number (googled it).
Topic archived. No new replies allowed.