fork download
  1. //Natalie Zarate
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cctype>
  5. using namespace std;
  6.  
  7. /*******************************************************************************
  8.  * digitsSum
  9.  *
  10.  * THis function will compute the sum of the series of numbers provided by the
  11.  * user
  12.  * ______________________________________
  13. // Prototype for digitsSum
  14. int digitsSum(cont char *string);
  15.  
  16. // Prototype for maxDigit
  17. char maxDigit(const char *string);
  18.  
  19. // Prototype for minDigit
  20. char minDigit(const char *string);
  21.  
  22. int main()
  23. {
  24. char numbers[5];
  25. int sum;
  26. // Prompt user for a series of single digit numbers
  27. cout << "Enter a series of 4 single digit numbers: " << endl;
  28. cin.getline(numbers, sizeof(numbers));
  29.  
  30. // Call digitsSum
  31. sum = digitsSum(numbers);
  32.  
  33. return 0;
  34. }
  35.  
  36. int digitsSum(const char *string)
  37. {
  38. int sum = 0; // OUTPUT - su of inputted series
  39.  
  40. // Step through array
  41. while(*string)
  42. {
  43. if(digits(*string))
  44. {
  45. sum += atoi(string);
  46. }
  47.  
  48. // Move to next element
  49.   string++
  50. }
  51.  
  52. return sum;
  53. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty