#include <iostream>
usingnamespace std;
void findLargest(string text);
void findSmallest(string text);
int main()
{
constint LENGTH = 100;
char s[LENGTH];
int total = 0, index;
cout << "Enter a series of numbers in a row " << endl;
cin >> s;
for (index = 0; index < strlen(s); index++)
{
total += s[index] - '0';
}
cout << "The total is " << total << endl;
cout << "The largest number is ";
findSmallest(s);
cout << "The smallest number is ";
findLargest(s);
return 0;
}
void findSmallest(string text)
{
char smallestNum;
for (int a = 0; a < sizeof(text); a++)
{
if (a == 1) smallestNum = text[1];
if (text[a] < smallestNum) smallestNum = text[a];
}
cout << smallestNum;
}
void findLargest(string text)
{
char largestNum;
for (int a = 0; a < sizeof(text); a++)
{
if (a == 1) largestNum = text[1];
if (text[a] >largestNum) largestNum = text[a];
}
cout << largestNum;
}
Line 28, 39: sizeof(text) does return the entire size of the string object text, which may contain sizes of some internal attributes of string. Use length() instead, which reports the number of actual characters of a string: text.length()