1. ## help with my program for class, PLEASE!!!

Hi, I am new to the forum. I am taking a CS class and this is our first program assignment and I am totally lost.

We have to create a program that reads the following data from a disk: (it must skip the symbols & only print the numbers)

@2,89#3,*67
\$187,3#%34,72#123#
*3*7*1#*3,4,8

289
367
1873
3472
123
371
348

We cannot use extractions, we must used nested loops.
I know how to read the info from disk but I am lost after that.

Professor suggested using sum = 0; sum = sum + digit -- in loops. -- Please just tell me how my loop process should start.

2. ## Re: help with my program for class, PLEASE!!!

Originally posted by acegillss
Hi, I am new to the forum. I am taking a CS class and this is our first program assignment and I am totally lost.

We have to create a program that reads the following data from a disk: (it must skip the symbols & only print the numbers)

@2,89#3,*67
\$187,3#%34,72#123#
*3*7*1#*3,4,8

289
367
1873
3472
123
371
348

We cannot use extractions, we must used nested loops.
I know how to read the info from disk but I am lost after that.

Professor suggested using sum = 0; sum = sum + digit -- in loops. -- Please just tell me how my loop process should start.
1. This isn't much of an importance, but instead of sum = sum + digit, you should use sum += digit which does the same.

For the loop, just use something like:
Code:
```for(int i = 0; i < 3; i++){
while(sum == 0){
sum += 1;
}
}```

3. dont know if this is much help or not but you it looks like you will end one loop for a given number evertime you encounter a # symbol.

Ignore everything else and extract/calculate the number from the remaining digits.

4. well if he wants you to read in stuff from a file then i am going to assume that it is a text file.

numbers as text have an ASCII value of 48 - 58. if its a text file you are reading them as characters anyway, so

char ch;
// get a char from the file
if ( ch < 48 || ch >58 )

that will exclude anything thats not a number. then you read those until you hit what determines the end of a number ( as curlious said, perhaps pound and newline ). then just string them together and print them. you could do the whole thing without using any math at all.

5. or you can use c-style strings... use isdigit();