#CPP last-will

31 messages · Page 1 of 1 (latest)

olive fractal
#

Not too sure what I am doing wrong for this one. Some help would be much appreciated.

// Task 1
namespace estate_executor {
    // Task 2
    int assemble_account_number(int secret_modifier) {
        return int assembled_account_number = {zhang::bank_number_part() + khan::bank_number_part() + garcia::bank_number_part()};
    }

    //Task 3
    int assemble_code(){
        return int code{(khan::blue() + zhang::blue() + garcia::blue()) * (khan::red() + zhang::red() + garcia::red())};
    }
}
tight furnace
#

Did you get an error message? What does it say?

half stirrup
# tight furnace Did you get an error message? What does it say?

An error occurred while running your tests. This might mean that there was an issue in our infrastructure, or it might mean that you have something in your code that's causing our systems to break.

Please check your code, and if nothing seems to be wrong, try running the tests again.

tight furnace
#

Is that your whole solution, i.e. did you delete anything above the line "// Enter your code below the lines of the families' information"

half stirrup
#

// Enter your code below the lines of the families' information

// Secret knowledge of the Zhang family:
namespace zhang {
int bank_number_part(int secret_modifier) {
int zhang_part{8'541};
return (zhang_part*secret_modifier) % 10000;
}
namespace red {
int code_fragment() {return 512;}
}
namespace blue {
int code_fragment() {return 677;}
}
}

// Secret knowledge of the Khan family:
namespace khan {
int bank_number_part(int secret_modifier) {
int khan_part{4'142};
return (khan_part*secret_modifier) % 10000;
}
namespace red {
int code_fragment() {return 148;}
}
namespace blue {
int code_fragment() {return 875;}
}
}

// Secret knowledge of the Garcia family:
namespace garcia {
int bank_number_part(int secret_modifier) {
int garcia_part{4'023};
return (garcia_part*secret_modifier) % 10000;
}
namespace red {
int code_fragment() {return 118;}
}
namespace blue {
int code_fragment() {return 923;}
}
}

// Enter your code below
namespace estate_executor
{
int assemble_account_number(int secret_modifier)
{
int bank_number_part = zhang::bank_number_part(secret_modifier) + khan::bank_number_part(secret_modifier) + garcia::bank_number_part(secret_modifier) ;
return bank_number_part;
}
int assemble_code (int code_fragment)
return (zhang::blue::code_fragment()+khan::blue::code_fragment()+garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment()+garcia::red::code_fragment());
}

tight furnace
#

There are a few issues: "return int ..." is not valid C++.
You can either define a variable of type int, e.g. with int my_variable = some_expression;
Or you can return something, e.g. with return some_expression;

half stirrup
#

In file included from /tmp/last-will/last_will_test.cpp:7:
/tmp/last-will/last_will.cpp:55:5: error: expected initializer before 'int'
55 | int sum = zhang::blue::code_fragment()+khan::blue::code_fragment()+garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment()+garcia::red::code_fragment();
| ^~~
/tmp/last-will/last_will.cpp:56:1: error: expected unqualified-id before 'return'
56 | return sum;
| ^~~~~~
make[2]: *** [CMakeFiles/last-will.dir/build.make:76: CMakeFiles/last-will.dir/last_will_test.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/last-will.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

#

int assemble_code (int code_fragment)

int sum = zhang::blue::code_fragment()+khan::blue::code_fragment()+garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment()+garcia::red::code_fragment();

return sum;
}

tight furnace
#

And khan::blue, zhang::blue, and garcia::blue are not functions, you cannot call them (khan::blue()).
I guess you want to call the code_fragment() functions, right? I will look like zhang::red::code_fragment()

half stirrup
#

yes

tight furnace
#

In that line 55 above you might want to check the parentheses. I can see a closing parenthesis after garcia::blue::code_fragment() without a matching opening one.

half stirrup
#

int assemble_code (int code_fragment)

int sum = (zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment());

return sum;
}

#

In file included from /tmp/last-will/last_will_test.cpp:7:
/tmp/last-will/last_will.cpp:55:5: error: expected initializer before 'int'
55 | int sum = (zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment());
| ^~~
/tmp/last-will/last_will.cpp:56:1: error: expected unqualified-id before 'return'
56 | return sum;
| ^~~~~~
make[2]: *** [CMakeFiles/last-will.dir/build.make:76: CMakeFiles/last-will.dir/last_will_test.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/last-will.dir/all] Error 2
make: *** [Makefile:91: all] Err

tight furnace
#

Please post your solutions again (everything following the line "// Enter your code below", I hope you didn't change anything above)

#

Oh, I just see: Is there an open curly brace missing between "int assemble_code (int code_fragment)" and " int sum = ..."

half stirrup
# tight furnace Please post your solutions again (everything following the line "// Enter your c...

// Enter your code below the lines of the families' information

// Secret knowledge of the Zhang family:
namespace zhang {
int bank_number_part(int secret_modifier) {
int zhang_part{8'541};
return (zhang_part*secret_modifier) % 10000;
}
namespace red {
int code_fragment() {return 512;}
}
namespace blue {
int code_fragment() {return 677;}
}
}

// Secret knowledge of the Khan family:
namespace khan {
int bank_number_part(int secret_modifier) {
int khan_part{4'142};
return (khan_part*secret_modifier) % 10000;
}
namespace red {
int code_fragment() {return 148;}
}
namespace blue {
int code_fragment() {return 875;}
}
}

// Secret knowledge of the Garcia family:
namespace garcia {
int bank_number_part(int secret_modifier) {
int garcia_part{4'023};
return (garcia_part*secret_modifier) % 10000;
}
namespace red {
int code_fragment() {return 118;}
}
namespace blue {
int code_fragment() {return 923;}
}
}

// Enter your code below
namespace estate_executor
{
int assemble_account_number(int secret_modifier)
{
int bank_number_part = zhang::bank_number_part(secret_modifier) + khan::bank_number_part(secret_modifier) + garcia::bank_number_part(secret_modifier) ;
return bank_number_part;
}
int assemble_code (int code_fragment)

int sum = (zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment());

return sum;
}

tight furnace
#

There is an open curly brace missing between "int assemble_code (int code_fragment)" and " int sum = ..."

tight furnace
#
int assemble_code (int code_fragment)

    int sum = (zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment()) (zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment());
return sum;

should look like this:

int assemble_code (int code_fragment)
{
    int sum = (zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment()) (zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment());
    return sum;
}
half stirrup
#

make[2]: *** [CMakeFiles/test_last-will.dir/build.make:70: CMakeFiles/test_last-will] Segmentation fault (core dumped)
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/test_last-will.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

tight furnace
#

Please post your whole solution again, and put them in a "code block". With a line of three backticks (```) before and after the code.

half stirrup
#

make[2]: *** [CMakeFiles/test_last-will.dir/build.make:70: CMakeFiles/test_last-will] Segmentation fault (core dumped)
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/test_last-will.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

tight furnace
#

Please post code in a code block. First a line with three backticks (```), then the code, then another line with three backticks (```).
Otherwise discord will format the code as markdown and swallow characters like an asterisk.

half stirrup
# tight furnace Please post code in a code block. First a line with three backticks (\`\`\`), th...

// Secret knowledge of the Zhang family:
namespace zhang {
    int bank_number_part(int secret_modifier) {
        int zhang_part{8'541};
        return (zhang_part*secret_modifier) % 10000;
    }
    namespace red {
        int code_fragment() {return 512;}
    }
    namespace blue {
        int code_fragment() {return 677;}
    }
}

// Secret knowledge of the Khan family:
namespace khan {
    int bank_number_part(int secret_modifier) {
        int khan_part{4'142};
        return (khan_part*secret_modifier) % 10000;
    }
    namespace red {
        int code_fragment() {return 148;}
    }
    namespace blue {
        int code_fragment() {return 875;}
    }
}

// Secret knowledge of the Garcia family:
namespace garcia {
    int bank_number_part(int secret_modifier) {
        int garcia_part{4'023};
        return (garcia_part*secret_modifier) % 10000;
    }
    namespace red {
        int code_fragment() {return 118;}
    }
    namespace blue {
        int code_fragment() {return 923;}
    }
}

// Enter your code below
namespace estate_executor
{
int assemble_account_number(int secret_modifier)
{
  int bank_number_part = zhang::bank_number_part(secret_modifier) + khan::bank_number_part(secret_modifier) + garcia::bank_number_part(secret_modifier) ;  
    return bank_number_part;
}
int assemble_code (int code_fragment)
{
    int sum = (zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment()) * (zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment());
return sum;
}
}```
tight furnace
#

The first function assemble_account_number() is correct. It takes a secret_modifier and passes it to other function to calculate the result.
The second function assemble_code() does not take an argument.

half stirrup
#

Thank you so much I am just stupid some times ❤️

tight furnace
#

No worries, we all are like that at times. Have fun with the other exercises!

ripe minnow
#

Hello, i'm having a diferent problem with this exercise. here's my code:

namespace estate_executor {
   int assemble_count_number(int secret_modifier) {
        int result = zhang::bank_number_part(secret_modifier) + khan::bank_number_part(secret_modifier) +         garcia::bank_number_part(secret_modifier);
        return result;
    }
   int assemble_code() {
        int code_red= zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment;
        int code_blue = zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment;
        return code_red * code_blue;
        
  }
}
#

here's what the compiler says:

We received the following error when we ran your code:
In file included from /tmp/last-will/last_will_test.cpp:7:
/tmp/last-will/last_will.cpp: In function 'int estate_executor::assemble_code()':
/tmp/last-will/last_will.cpp:51:80: error: pointer to a function used in arithmetic [-Werror=pointer-arith]
   51 |         int code_red= zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment;
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/last-will/last_will.cpp:51:80: error: invalid conversion from 'int (*)()' to 'int' [-fpermissive]
   51 |         int code_red= zhang::red::code_fragment() + khan::red::code_fragment() + garcia::red::code_fragment;
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                |
      |                                                                                int (*)()
/tmp/last-will/last_will.cpp:52:84: error: pointer to a function used in arithmetic [-Werror=pointer-arith]
   52 |         int code_blue = zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment;
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/last-will/last_will.cpp:52:84: error: invalid conversion from 'int (*)()' to 'int' [-fpermissive]
   52 |         int code_blue = zhang::blue::code_fragment() + khan::blue::code_fragment() + garcia::blue::code_fragment;
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                    |
      |                                                                                    int (*)()
tight furnace
#

Please create new threads for new problems.
In this case: Lines 51 and 52 call two functions (with an empty pair of parentheses) but not the third one.
That's why the compiler complains that garcia::blue::code_fragment (implicitly converted to a function pointer) cannot be used in an arithmetic expression.