Raindrops exercise tests pass locally but all fail when submitting

Hi guys,

I just wrote my solution for the raindrops exercise in the C++ track. Please see below my solution, test error example in the Exercism editor and my local tests results. If anyone could help point me in the right direction about why they’re failing after submission I’d appreciate it :slight_smile:

Example of online editor error upon submission
In file included from /tmp/raindrops/raindrops_test.cpp:3: /tmp/raindrops/raindrops_test.cpp: In function 'void ____C_A_T_C_H____T_E_S_T____0()': /tmp/raindrops/raindrops_test.cpp:10:31: error: 'convert' is not a member of 'raindrops' 10 | REQUIRE("1" == raindrops::convert(1)); | ^~~~~~~

Running the tests locally

[main] Building folder: raindrops 
[build] Starting build
[proc] Executing command: /opt/homebrew/bin/cmake --build /Users/mitch/Exercism/cpp/raindrops/build --config Debug --target all -j 14 --
[build] [ 25%] Building CXX object CMakeFiles/raindrops.dir/raindrops_test.cpp.o
[build] [ 50%] Linking CXX executable raindrops
[build] [100%] Built target raindrops
[build] ===============================================================================
[build] All tests passed (18 assertions in 18 test cases)
[build] 
[build] [100%] Built target test_raindrops
[driver] Build completed: 00:00:00.825
[build] Build finished with exit code 0

My solution

#include "raindrops.h"
#include <string>

namespace raindrops {
    std::string convert (int number) {
        std::string sounds = "";

        if (number % 3 == 0) {
            sounds = sounds + "Pling";
        }

        if (number % 5 == 0) {
            sounds = sounds + "Plang";
        }

        if (number % 7 == 0) {
            sounds = sounds + "Plong";
        }

        if (sounds == "") {
            sounds = std::to_string(number);
        }

        return sounds;
    }
} 

The error message “error: ‘convert’ is not a member of …” tells when compiling the tests the compiler does not know the function raindrops::convert (“not a member”).

Did you declare the function convert in the .h file?

Thanks for responding!

Here is my raindrops.h file

#if !defined(RAINDROPS_H)
#define RAINDROPS_H
#include <string>

namespace raindrops {
    std::string convert(int number);
} 

#endif // RAINDROPS_H

That’s strange. I just copied your two snippets into the web editor and ran the tests, everything passed.

Did you submit both files?

It was as easy as that. After submitting both files the tests have passed. Thank you!

1 Like

Great to hear. Have fun!

1 Like