So my assignment for school is as follows:
Write a program that asks the users to enter a series of single digit numbers with nothing separating them. Read the input as a C-string object. The program should display the sum of all the single-digit numbers in the string. For an example, if the user enters 2518, the program should display 16, which is the sum of 2, 5, 1, and 8. The program should also display the highest and lowest digits in the string.
Example Output:
Enter a series of digits with no spaces between them.
2518
The sum of those digits is 16
The highest digit is 8
The lowest digit is 1
Here is my code:
#include<iostream>
#include <cstdlib>
#include<cstring>
using namespace std;
char input[100];
int x[100];
void user_input(char[]);
void char_int_conversion(char[],int[]);
void lowest_highest_digit(int[]);
int main()
{
user_input(input);
char_int_conversion(input,x);
lowest_highest_digit(x);
return 0;
}
void user_input(char input[])
{
cout<<"Enter a series of digits with no spaces between them";
cin>>input;
}
void char_int_conversion(char input[],int x[])
{
for(int i=0;i<=100,i++;)
x[i]=atoi(input[i]);
}
void lowest_highest_digit(int x[])
{
int lowest=x[0];
int highest=x[0];
int total=0;
for(int i=0;i<=100,i++;)
if(x[i]<lowest)
lowest=x[i];
for(int i=0;i<=100,i++;)
if(x[i]>highest)
highest=x[i];
for(int i=0;i<=100,i++;)
total = total+x[i];
cout<<"The sum of those digits is: "<<total<<endl
<<"The highest digit is: "<<highest<<endl
<<"The lowest digit is: "<<lowest<<endl;
}
on line 31 where i use the atoi function to convert the char array input into the integer array x, i get an error saying argument of type"char is incompatible with parameter of type "const char".
if i delete the [i] from atoi(input[i]) I can get the program to build, but all the output variable then just equal to 0;
Any help would be most appreciated!