okay so this is what i've got
Code:
// this program will read in a string of char's ending in a period, and then calculate
// the checksum, and print it out in both the char and int formats
#inclde<stdio.h>
#define START_CHAR ' '
#define END_CHAR '.'
int check_sum(int sum) //function prototype
int main(void)
{
int char_code,sum,checksum,x; //declared variables
char letter; //declared character
/*ask for input*/
printf("Enter a message ending in a period; or a period only to quit.\n\n");
while(scanf(" %c", &letter) != '.')
{
/*initialize sum at 0, until char_code = '.' , add it to the sum*/
for(sum = 0; char_code != (int)END_CHAR; sum += char_code)
{
scanf(" %c", &letter); //read in string ending in period
char_code = (int)letter; //swap character to integer
}
checksum = check_sum(sum); // call function
printf("Checksum: %c %d\n", (char)checksum, (int)checksum); //print checksum
}
return(0);
}
and then the function is as i have listed it above, but its giving me bogus answers... when i remove the while loop the answers come out correctly. anybody see what it is i'm doing wrong within the while loop?