I have a string with n elements and the exercise asks me to display the highest figure of each number.
The code I have wrote so far displays the first figure of the each number that has been introduced.
Please do not use more advanced stuff like functions,I'm a begginer.
if(c>max)
you need to check this with the while() loop still running, currently you're checking after the while() loop has terminated and hence you're left with the first digit:
#include <iostream>
int main()
{
int number{};
int maxDigit{};
std::cout << "Enter a number : \n";
std::cin >> number;//input validation required
while (number != 0)
{
if ((number % 10) > maxDigit) //Remainder of number / 10
{
maxDigit = number % 10;
}
number /= 10; //remove the last digit
}
std::cout << "The largest number was " << maxDigit << "\n";
}