Assert function in C++ using cassert library – How can I declare the variables in the test function?

  c++
#include <iostream>
#include <string>
#include <cassert>

using namespace std;

void test();

void test() { //my attempted test function in order to ensure the program works correctly

string answ1 = "noooooob";
string answ2 = "saaaaaadie";
string answ3 = "trish";

assert(answer(answ1) == "nob"); //this is where i get the compile error that "answer" not declared
assert(answer(answ2) == "sadie");
assert(answer(answ3) == "trish");

cout << "All test cases passed!" << endl;

}

int main() {

    int i = 0;
    string output;
    string input;
    char x;

    getline(cin, input); //input

    output += input[0];
    x = input[0];


    while (i < input.length()) {

        i++;
        if (input [i] != x) {
            output += input[i];
        }
        x = input[i];
    }

    cout << output << endl;

    test();

    return 0;
}

All I’m really asking is how to declare the "answer" variable in the assert function. Maybe I’m doing it completely wrong, and my apologies if so. I’m pretty new to the coding scene. Do I need to make a string that would loop through the current for loop in my main function? Any help is much appreciated.

Source: Windows Questions C++

LEAVE A COMMENT