#Quick question regarding Triangle question using C++

12 messages · Page 1 of 1 (latest)

lilac locust
#

What should be the return value if the given values are not a triangle
`#include "triangle.h"

namespace triangle {
// TODO: add your solution here
flavor kind (float a, float b,float c){
if(a + b > c && b + c > a && a + c > b){
if(a == b&& b == c){
return flavor::equilateral;
}else if(a == b || a == c || b == c){
return flavor::isosceles;
}else {
return flavor::scalene;
}
}
return flavor:: ;
}
}`

`#pragma once

namespace triangle {

// TODO: add your solution here
enum flavor{ equilateral,isosceles,scalene};
flavor kind (float a, float b,float c);

}`

outer bison
#

What do the tests say when you run them? The tests should indicate the expectations.

kind vapor
#
#include "triangle.h"

namespace triangle {   
// TODO: add your solution here
    flavor kind (float a, float b,float c){
        if(a + b > c && b + c > a && a + c > b){
            if(a == b&& b == c){
                return flavor::equilateral;
            }else if(a == b || a == c || b == c){
                return flavor::isosceles;
            }else {
                return flavor::scalene;
            }
         }
        return flavor:: ;
    }
}

#pragma once

namespace triangle {

// TODO: add your solution here
    enum flavor{ equilateral,isosceles,scalene};
    flavor kind (float a, float b,float c);

}
winged portal
#

since it doesn't belong to any value in the flavor enum, i think the test expects you to throw. you should look at the test case where it says REQUIRE_THROWS_AS

lilac locust
lilac locust
#

We received the following error when we ran your code:

/tmp/triangle/triangle.cpp: In function 'triangle::flavor triangle::kind(float, float, float)': /tmp/triangle/triangle.cpp:15:25: error: expected unqualified-id before ';' token 15 | return flavor:: ; | ^ make[2]: *** [CMakeFiles/triangle.dir/build.make:90: CMakeFiles/triangle.dir/triangle.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/triangle.dir/all] Error 2 make: *** [Makefile:91: all] Error 2

outer bison
#

REQUIRE_THROWS_AS(triangle::kind(1, 1, 3), std::domain_error);

#

That tells you what it expects you to do

lilac locust
outer bison
#

It's supposed to throw an error, not return an error. But yes, it expects a std::domain_error.

lilac locust
#

`#include "triangle.h"

namespace triangle {
// TODO: add your solution here
flavor kind (float a, float b,float c){
if(a + b > c && b + c > a && a + c > b){
if(a == b&& b == c){
return flavor::equilateral;
}else if(a == b || a == c || b == c){
return flavor::isosceles;
}else {
return flavor::scalene;
}
}
throw std::domain_error("");
}
} // namespace triangle#pragma once
#include <stdexcept>

namespace triangle {

// TODO: add your solution here
enum flavor{equilateral,isosceles,scalene};
flavor kind (float a, float b,float c);

} `