mercredi 5 juillet 2017

C++ Using for loops when you don't know when the iteration would end

So I have this code for c++ (not c++11) #include

using namespace std;

int calcTrip (string s) {
    int ans = 1;
    for (int i = 0; i < sizeof(s); i++) {
        char c = s[i];
        ans = ((ans*(c - 'A' + 1)) );
    }
    return ans;

}
int main() {

    string a1, a2;
    cin >> a1 >> a2;
    cout << calcTrip(a1) << endl;
    if (calcTrip(a1) != calcTrip(a2)) {
        cout << "STAY" << endl;
    }
    else {
        cout << "GO" << endl;
    } 

}

For my forloop in the variable calctrip, if I do i

Thanks.

P.S And I know how to do this in c++ 11, but for class, I need to know how to do it in c++ 98

Aucun commentaire:

Enregistrer un commentaire