-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA28c-strings.cpp
More file actions
42 lines (34 loc) · 843 Bytes
/
A28c-strings.cpp
File metadata and controls
42 lines (34 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// C-Strings
// By Alina Corpora, Emily Dayanghirang, and Sarra Osman
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
using namespace std;
int main()
{
const int SIZE = 16;
char line[SIZE];
int count = 0,
total = 0;
while (line[count] != '\0')
{
line[count] = 0;
count++;
}
// Prompt user
cout << "\nEnter a series of single characters with no more than\n"
<< (SIZE-1) << " characters (alphabets and digits) and with nothing\n"
<< "separating them: ";
cin >> setw(16) >> line;
cout << "\nThe sum of all the single-digit numbers in the string:\n";
for(int i= 0; i < SIZE; i++)
{
if(line[i]>'0' && line[i]<='9')
{
total += line[i]-'0';
}
}
cout << total;
return 0;
}