i need help with a loop program

Integers are read until the number 0 is met. Display all triplets of numbers read consecutively, with the property that they can represent the sides of an isosceles triangle.Create this program as simple as possible without subprograms and using a loop..Please :**
Last edited on
denis,

How about you have a go at this yourself?- you don't appear to write much code, but you get an awful lot of help.

"Isosceles" - two (and presumably not three) sides equal; so two of the numbers are the same.

"Triangle" - so:
- all strictly positive;
- they satisfy the triangle inequality; in this case, the non-equal one is less than the sum of the other two.
you didn't helped me at all
i need the program not your advice
and after all you improve your skills
After a certain point, helping novices does not appreciably improve one's own skills. I speak from experience.

Please demonstrate that you've at least made a basic attempt to solve the problem.

-Albatross
corepower wrote:
and after all you improve your skills
corepower wrote:
i need the program not your advice

Sounds counter-intuitive to me.

Anyway, my advice is:
(1) You at least try writing some code.
(2) Your code selects the triplets of integers of the form a,a,b (in some order), where a and b are both positive and b < 2a.
i need the program


No you don't. You need air, water, food etc but not a program. You would like a program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <algorithm>
#include <utility>

int main()
{
	for (int nos[3] {}; (std::cout << "Enter 3 nos (non-num to quit): ") && (std::cin >> nos[0] >> nos[1] >> nos[2]); ) {
		std::sort(nos, nos + 3);

		const auto adjac {std::adjacent_find(nos, nos + 3)};

		if (std::all_of(nos, nos + 3, [](int n) {return n > 0; }) && (adjac != nos + 3)) {
			if (adjac != nos)
				std::swap(*nos, *(nos + 2));

			if (nos[2] < nos[0] + nos[1]) {
				std::cout << "is isosceles\n";
				continue;
			}
		}
		std::cout << "isn't isosceles\n";
	}
}


If this is for an exercise, I hope you understand it - as your teacher should realise you haven't written it.
ok from now i will try to write code by myself
Last edited on
can you make this program just with iostream?
i mean without continue and all that stuff
ok from now i will try to write code by myself
5 hours later...
can you make this program just with iostream?


What have you tried doing?
Last edited on
done, it works now
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
37
#include <iostream>

using namespace std;

int main()
{
	for (int num[3] {}; (cout << "Input 3 numbers : ") && (cin >> num[0] >> num[1] >> num[2]); ) {


		         if (num[0]==num[1]) {
				cout << "is isosceles\n";

			}
			else if (num[1]==num[2]) {
				cout << "is isoscles\n";

			}
			else if (num[0]==num[2]) {
				cout << "is isosceles\n";

			}


					else if(num[0]==0){
                    cout << "isnt isosceles\n";
                    break;
					}
					else if(num[1]==0){
                    cout << "isnt isosceles\n";
                    break;
					}
					else if(num[2]==0){
                    cout << "isn's isosceles\n";
                    break;
					}
		}
}
where is the mistake here?
Shouldn't the tests for 0 be before the tests for side equality? Also, just because 2 sides are equal this doesn't mean it's a triangle. To be a valid triangle, the 3rd side has to be less than the sum of the other 2 sides.
Topic archived. No new replies allowed.