I am supposed to write a program that lets the user enter random numbers from the keyboard into a string and then the program should total all the numbers and output the total for instance if a user enters 1,2,3,4,5 then it would display the total as "15". I have it to where its correctly displaying the total of the numbers entered but I'm also supposed to display the maximum and minimum digits entered. I can't get this to work correctly because I don't know how to get it to only scan the entered numbers in the string, not the entire randomized string. Here is my code ... thanks in advance for any help!
#include <iostream>
#include <cstdlib>
int main()
{
char numbers[100];
int total = 0, minimum, maximum;
std::cout << "Enter a series of numbers in a row " << std::endl;
std::cin >> numbers;
for (int i = 0; i < strlen(numbers); i++)
{
total += numbers[i] - '0';
for (int i = 0; i < strlen(numbers); i++)
{
minimum = numbers[0];
maximum = numbers[0];
if(numbers[i] < minimum)
minimum = numbers[i];
if(numbers[i] > maximum)
maximum = numbers[i];
}
}
std::cout << "The total is: " << total << std::endl;
std::cout << "The maximum number is: " << maximum << std::endl;
std::cout << "The minimum number is: " << minimum << std::endl;
}
#include <iostream>
#include <cstdlib>
int main()
{
char numbers[100];
int total = 0, minimum, maximum;
std::cout << "Enter a series of numbers in a row " << std::endl;
std::cin >> numbers;
minimum = numbers[0];
maximum = numbers[0];
for (int i = 0; i < strlen(numbers); i++)
{
total += numbers[i] - '0';
}
for (int i = 1; i < strlen(numbers); i++)
{
if(numbers[i] < minimum)
minimum = numbers[i];
if(numbers[i] > maximum)
maximum = numbers[i];
}
std::cout << "The total is: " << total << std::endl;
std::cout << "The maximum number is: " << maximum << std::endl;
std::cout << "The minimum number is: " << minimum << std::endl;
}