Creating a Triangle From array

thank you its finished
Last edited on
If you're going to keep deleting your questions once you've gotten help, then people are going to stop wanting to help you.
can someone help me with whole code?
No. We generally do not do that. However if you post what you have, and outline problems you encountered, we might help you (and give advice how to improve your existing code)

You have several steps which you need to do:
user will input number of sides to choose from
Get amount from user
so it means and array will have to allocate memory based on the first number
Create array/vector/container of that size
then second number input is the perimeter of the triangle
Get input from user and store it.
you will fill the array with the sides
Get user input in a loop filling your array.

Did you have problems with any of these?

No I will give some hints on your last problem:
if its possible to create the triangle from any 3 sides from the whole array
Rough algorithm is simple: pick first three sides, check if they have proper perimeter, check if they form a valid triangle. Then pick next three, and so on.

Naive loop:
1
2
3
4
for(i = [0, size))
    for(j = [0, size))
        for(k = [0, size))
            check_if_fit(array[i], array[j], array[k])
This will loop through all combinations and is guaranteed to find each possible triangle. (actually it will find it no less than 6 times).
When you will have working code, you can start optimising (removing repetitions and general speedup), but this should be done after you have working code.

P.S. Posting same question again and again will not give you help if you never react to advices given and questions asked in previous threads.
alright
Last edited on
i have never seen an loop looking like this
Because it is pseudocode: it describes intention, not created to plugging into compiler. It just means loop ffrom 0 to size.

how can i remove repeating ?
First of all, make your code work. Then you can start improving it.

Remember three steps: first make it work, then make it right, and, finally, make it fast.
Make code which works first. Removing repetitions comes next.
ok
Last edited on
Answering here instead of private message: firs of all, throw out your break. It is not needed and will break your code.
Second: you do not check if trianle made from these sides is correct.
Third: if it outputs 10 times, then there is 10 possible combinations (with repetition, but that is going to be fixed later). Output sides instead of simple notion if there is fit or not. Then post examples of input (your sides) and output (which triads of sides program has found).

After it start finding all needed combinations we will move to second stage: make it right, and will remove most of the repetitions.
Topic archived. No new replies allowed.