#My C++ Triangle thing is fully functioning, but doesn't work on Exercism.

18 messages · Page 1 of 1 (latest)

snow ingot
#

Is this what you submitted on Exercism? The function is named main() and it prints some sentence but the tests on Exercism call a function named kind() and expect it to return a result.

#

Take a look at the tests. This is the first one:

TEST_CASE("isosceles_triangles_have_last_two_sides_equal")
{
    REQUIRE(triangle::flavor::isosceles == triangle::kind(3, 4, 4));
}

It calls the function triangle::kind with three arguments, and expects a result that is equal to triangle::flavor::isosceles
Reading the tests is important, they specify all the technical details.

#

Whenever C++ programmers think of a type with a few distinct values (and they can even name those values) they think of an enum or even better: enum class. You have to define that type in the .h file.

unique sphinx
#

like Siebenschlaefer said, the tests are telling you the return type it expects

#

REQUIRE(triangle::flavor::equilateral == triangle::kind(2, 2, 2)); means that kind(2, 2, 2) needs to return an enumerator of class flavor of value equilateral

#

for the tests, the left side is the expected value

#

so in your h file, you need to add a declaration to the triangle namespace for that enum type, and then use that enum type in your definition of kind

#

no, not at all

#

if you haven't done that associated learning exercise yet, that should point you in the right direction

#

that should give you what you need for Triangle yes

#

namespaces are a way to organize and contain the functions and types and constants you use, you use them specifically because you don't want those things to be global

snow ingot
snow ingot
#

Multiple issue:

  • kind returns an int. This int cannot be compared (without casts) with an an enum class.
  • The function in the .h file returns flavor. This `flavor is a type, not a value. You have to return one of the three values.
  • The .cpp file also defines kind. You can only have one definition for a function (the so-called ODR rule)
  • The function in the .cpp file assigns something to flavor. But flavor is a type, not a variable.
snow ingot
#

This error without error message often happens when a solution throws an exception where the tests do not expect one.

#

There's a semicolon missing after the throw statement.

#

Take a look at the test "very_small_triangles_are_legal". It calls triangle::kind(0.4, 0.6, 0.3).
But since the parameters in your solution have the type int these arguments all get converted to 0, and then the function throws an exception where none is expected.

#

And one last thing that I noticed: You might want to double-check the type of the exception that the tests expect.