How can I find the lowest and highest digit from a string?

Going by the following code what would be the optimal way to find the higher and lower digit of the string?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  int main()
{
    string digits;
    int total = 0, num;

    cout << "Enter a string of digits" << endl;
    cin >> digits;

    for (int i = 0; i < digits.length(); i++)
    {   
        cout << digits.at(i) << endl;
        istringstream(digits.at(i)) >> num;
        cout << num << endl;    
        total += num;
    }

    cout << "Total: " << total << endl;

    // Display high/low int in string
}
You need two further variable where you store the max/min values and compare (and set if applies) them with the actual number.
Topic archived. No new replies allowed.