# Thread: hey beagleman

1. Originally Posted by God
im not sure what you mean. it scans and then sums each character before re-checking its condition. if just a period is entered it will scan that period and enter 46 into sum. the if statement uses that and works fine.
Let's say a is 10 and b is 20.

If you enter 'ab.', when the program begins, sum=0. When a is scanned and its value added, sum=10. When b is scanned and its value added, sum=30 (20+10). When the period is scanned and added, sum=30+46=76. It will never be equal to 46 unless you JUST enter a period.

2. yeah i know. the program is supposed to terminate when you enter the period.

the user is supposed to continue to be prompted to enter messages and have them evaluated until he enters just a period, then the program is supposed to end. thats why the loops that the sum != 46 condition

3. God sum will NEVER BE EQUAL TO 46. Illustrate an example where sum becomes 46 for anything other than just a period.

4. Did you not get this example?

Originally Posted by Rayne
Let's say a is 10 and b is 20.

If you enter 'ab.', when the program begins, sum=0. When a is scanned and its value added, sum=10. When b is scanned and its value added, sum=30 (20+10). When the period is scanned and added, sum=30+46=76. It will never be equal to 46 unless you JUST enter a period.

5. Im almost there God, today I made a program that plays this simple logic game.

6. Originally Posted by Rayne
God sum will NEVER BE EQUAL TO 46.
This. Why don't you just use a condition using the character "." instead?

... This would be so much easier if you were using arrays.

7. Originally Posted by God
its a lab for my class. heres what its supposed to do:
User enters a message, ending with a period. Convert the characters into their integer values, sum up the values, get the remainder of that sum when divided by 64, then display that value as a character.

most of it works fine, if i take out the main loop and just run whats inside of it, it gives back the right values for the messages and terminates when i just put in a period. but the program is supposed to prompt the user to keep entering messages UNTIL they just enter a period.

i think the problem is this:
the second while loop goes until it encounters a period, does all its shit, then goes back, the main loop says the sum wasn't 46(integer value of '.') so it runs the program again, but the last thing the second while loop scanned in was a period, so it still retains that period and is in an infinite loop.

i can get it out of an infinite loop if i give checksum some random value after everything else, since then the last value isn't a period anymore, but then it fucks with the sums. i need to find a way to clear scanf or something.

Code:
```#include<stdio.h>
# define SENTINEL "."
int main()
{ char checksum;
int sum=0;
int rem;

printf("\n Enter a string ending with a period: ");
while(checksum!=SENTINEL)
{ scanf("%c",&checksum);
sum+=(int) checksum;
}

rem=sum%64;
printf("\n %c",rem);
return 0;
}```

8. Bah, You Nerds!

9. Dang, completely forgot to initialise checksum even though I told you to do it

Code:
```#include<stdio.h>
# define SENTINEL '.'
int main()
{ char checksum='\0';
int sum=0;   int rem;
printf("\n Enter a string ending with a period: ");
while(checksum!=SENTINEL)
{ scanf("%c",&checksum);
sum+=(int) checksum;
}
rem=sum%64;
printf("\n %c",rem);
return 0;
}```
Now this will definitely work.

Page 3 of 3 First 123

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•