String and loop exercises

These are from 18 November, and take the place of quiz 5.

q5subst.cpp

#include <iostream>
using namespace std;

int main()
{
    string message = "Hello there, world!";
    cout << message << "\n";
    cout << message[17] << message[4]
         << message[4] << message[15]
         << "\n";
    cout << message[message.length()-1] << "\n";
    // Go right to left in that string
    for(int i = message.length()-1; i >= 0; i-=1)
    {
        cout << i << ": " << message[i] << "\n";
        //cout << message[i];
    }
    cout << "\n";
    return 0;
}

wacky.cpp

#include <iostream>
using namespace std;

// What is the output? (You don't have to go all the
// way to 40, just enough to "wrap" around the string
// a few times.)

int main()
{
    string s = "testing12345";
    int k = 0;
    for(int i = 1; i < 40; i++)
    {
        k = (k + i) % s.length();
        cout << s[k];
    }
    cout << "\n";
    return 0;
}