This should get you started. You seemed to be stuck on how to loop on char values. for supports that because char is an integer type. In ASCII and all derivative character sets, the Basic Latin uppercase letters are sequential and in the order of the English alphabet so you can iterate over a range of them and use subtraction to determine how far one is from 'A'—that forms a natural mapping: A ↔ 0, B ↔ 1,… Z ↔ 25.
I had some questions about the meaning of "between the starting character and the ending character" so I wrote down what I thought the answers should be. For example: What's between B and B? (See BB_should_equal_B below.) This is in the form of "unit tests".
Unit testing is a technique that is taught way too late. You don't have to understand much to get started. I used the Google Test framework. If you have trouble building the library and using the include files in your project, perhaps someone like a TA can help you. (They might even thank you for showing them unit testing.)
In any case, you can see how it helps define what your goals are and gives you a place to write down some test values. Other than the funky syntax, a test has:
- a name that describes the requirement.
- a test framework assert that checks the actual value vs the expected (correct) value.
.
#include <cassert> #include "gtest/gtest.h" using namespace std; int sumConsonants(char first, char last); class CharSumTestFixture : public ::testing::Test { }; TEST_F(CharSumTestFixture, AA_should_equal_zero) { ASSERT_EQ(sumConsonants('A', 'A'), 0); } TEST_F(CharSumTestFixture, BB_should_equal_B) { ASSERT_EQ(sumConsonants('B', 'B'), 'B'); } TEST_F(CharSumTestFixture, BCD_should_equal_B_plus_C_plus_D) { ASSERT_EQ(sumConsonants('B', 'D'), 'B' + 'C' + 'D'); } TEST_F(CharSumTestFixture, AE_should_equal_B_plus_C_plus_D) { ASSERT_EQ(sumConsonants('A', 'E'), 'B' + 'C' + 'D'); } TEST_F(CharSumTestFixture, AZ_should_equal_A_through_Z_minus_A_minus_E_minus_I_minus_O_minus_U) { auto n = 'Z' - 'A' + 1; auto gauss = n * (n + 1) / 2; auto offset = 'A' - 1; auto sumAZ = gauss + n * offset; ASSERT_EQ(sumConsonants('A', 'Z'), sumAZ - 'A' - 'E' - 'I' - 'O' - 'U'); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } int sumConsonants(char first, char last) { // Assertions are used to communicate, during development and maintenace, already accepted pre-conditions. // They are not for handling cases where those conditions do not exist. assert((first >= 'A') && (first <= 'Z')); assert((last >= 'A') && (last <= 'Z')); int sum = 0; for (auto letter = first; letter <= last; letter++) { sum += letter; // BUG must not add non-consonants } return sum; }

forloop...