Thread: C Program Help!

  1. #1
    Registered User
    Join Date
    Oct 2004

    C Program Help!

    "write a program that accepts single-line messages ending with a period and displays the checksum character for each message. Your program should continue displaying checksumuntil the user enters a line with only a period."

    that is what i'm asked to do, i tried to program it, but i don't know how to move on from what i got, please help me

    /* This program will accept single-line messages ending with a period and
       display the checksum character for each message                              */
    #include <stdio.h>
    #include <math.h>
            int checksum;           /* output - checksum            */
            char single_message;    /* input - single-line message  */
            int check;
            char myarray[150];
            char period;
            char c;                 /* temporary character          */
            int i;
            int j;
            double y;
            /* Get the single-line message ending with a period     */
            printf("Enter a single-line message> ");
            scanf ("%s", myarray);
            /* Loop statement                                       */
            do {
            while q = getcchar ();
            /* Calculate the checksum                                       */
            y += c;
            do {
            while(getchar()!='.')  //
            return 0;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    First off, you should learn how to get a line from the user correctly. Then, you need to think about the logic of what it is you're trying to do, and rewrite your program.

    Hope is the first step on the road to disappointment.

  3. #3
    Join Date
    May 2004
    is this safe?
    char c;
    double y;
    y += c;
    not to mention that they dont have values to add together anyway

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    >int main(void)
    Woohoo! Less than 50 posts and not using void main? That has to be some sort of record.

    >/* Get the single-line message ending with a period */
    >printf("Enter a single-line message> ");
    Too bad the user can't see that comment. If termination by a period is as important to your program as it appears, you need to be sure that the user knows to include it.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM