Page 1 of 3 123 LastLast
Results 1 to 25 of 59

Thread: hey beagleman

Hybrid View

  1. #1
    what about .. eyebrows God's Avatar
    Join Date
    Apr 2005
    Location
    among the people
    Posts
    49,682

    Default hey beagleman

    i might let you edit your profile if you tell my why this program gives me an infinite loop for all statements other than '.'



    #include <stdio.h>
    #include <stdlib.h>

    #define SENTINEL '.'

    int
    main()
    {

    char checksum, finalcheck;
    int sum, check;

    sum = 0;

    while(sum != 46)
    {

    printf("Enter a one-line message. Complete your message with a period.\n");
    printf("Enter a message: ");

    while(checksum != SENTINEL)
    {
    scanf("%c", &checksum);
    sum += (int)checksum;
    }
    if(sum != 46)
    { check = sum % 64;

    finalcheck = (char)(check + 32);

    printf("Checksum: %c\n", finalcheck);
    }
    else
    printf("Program ended.\n");


    }

    return(EXIT_SUCCESS);
    }

  2. #2
    what about .. eyebrows God's Avatar
    Join Date
    Apr 2005
    Location
    among the people
    Posts
    49,682

    Default

    i have to submit it at midnight so you have til then to find whats wrong and give me enough time to fix it.

  3. #3
    what about .. eyebrows God's Avatar
    Join Date
    Apr 2005
    Location
    among the people
    Posts
    49,682

    Default

    you did say the only way you could defeat dogar was in a computer competition. who knew it would come to fruition.

  4. #4
    princeso Kirby's Avatar
    Join Date
    Mar 2009
    Location
    Candy Castle
    Posts
    18,920

    Default

    God go to cosmo and ask flaming flamingo, he is real good with the code.

    He made astriods.

  5. #5
    I do things like get in a taxi and say, "The library, and step on it. Lord's Avatar
    Join Date
    Nov 2007
    Posts
    8,713

    Default

    what's astroids
    Well, I open my eyes and I see things. I've seen spirits moving through the walls. I've seen a vortex coming through the wall. I've seen amorphous little balls of light bouncing all around in the front yard through the window. I've seen giant bugs on the floor. I was in a hotel room in Amarillo, Texas, and all I remember is standing on the bed and seeing the whole wall in front of me filled with lights that were [makes popping sound] popping like popcorn out of the wall. Then I'll wake up and I go "Wow, I was standing on my bed and staring at this wall."

  6. #6
    I do things like get in a taxi and say, "The library, and step on it. Lord's Avatar
    Join Date
    Nov 2007
    Posts
    8,713

    Default

    this thread is exciting
    Well, I open my eyes and I see things. I've seen spirits moving through the walls. I've seen a vortex coming through the wall. I've seen amorphous little balls of light bouncing all around in the front yard through the window. I've seen giant bugs on the floor. I was in a hotel room in Amarillo, Texas, and all I remember is standing on the bed and seeing the whole wall in front of me filled with lights that were [makes popping sound] popping like popcorn out of the wall. Then I'll wake up and I go "Wow, I was standing on my bed and staring at this wall."

  7. #7
    princeso Kirby's Avatar
    Join Date
    Mar 2009
    Location
    Candy Castle
    Posts
    18,920

    Default

    You never played astriods?

  8. #8
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,491

    Default

    Quote Originally Posted by Kirby View Post
    You never played astriods?
    ASTEROIDS you moron

  9. #9
    I do things like get in a taxi and say, "The library, and step on it. Lord's Avatar
    Join Date
    Nov 2007
    Posts
    8,713

    Default

    you mean like the 1980s computer game?
    Well, I open my eyes and I see things. I've seen spirits moving through the walls. I've seen a vortex coming through the wall. I've seen amorphous little balls of light bouncing all around in the front yard through the window. I've seen giant bugs on the floor. I was in a hotel room in Amarillo, Texas, and all I remember is standing on the bed and seeing the whole wall in front of me filled with lights that were [makes popping sound] popping like popcorn out of the wall. Then I'll wake up and I go "Wow, I was standing on my bed and staring at this wall."

  10. #10
    Beginning Trainer
    Join Date
    Mar 2012
    Posts
    4

    Default

    Wow..
    Doesn't give me much time..
    I will do my best to figure it out.. :L
    If I get an answer, I'll post it.

  11. #11
    Defenestration is imminent pichubro's Avatar
    Join Date
    Mar 2005
    Location
    Kaleidoscope Of Mathematics
    Posts
    18,231

    Default

    I think Yoshi just revealed himself as beagleman.

  12. #12
    VVVV Look 4 balls Khaous's Avatar
    Join Date
    Feb 2010
    Posts
    3,260

    Default

    you have 2 hours if gods in my timezone. GET CODING MAN

  13. #13
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,491

    Default

    indent your code. its painful to read.

  14. #14
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,491

    Default

    also i dont understand what youre trying to do here. at first i assumed you were trying to count the number of characters but youre doing weird arithmetic with sum. either way, i think the cause of the infinite loop is that after the second while, though youre asking them to type a sentence, youre only scanning the first character which will never be a period unless you just enter a period. the loop only stops when the scanned character is a period so yeah infinite loop for anything other than a period.

  15. #15
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    Quote Originally Posted by Rayne View Post
    also i dont understand what youre trying to do here. at first i assumed you were trying to count the number of characters but youre doing weird arithmetic with sum.
    Yeah, why are you converting the characters to their integer values and adding them together?
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

  16. #16
    what about .. eyebrows God's Avatar
    Join Date
    Apr 2005
    Location
    among the people
    Posts
    49,682

    Default

    Quote Originally Posted by Rayne View Post
    also i dont understand what youre trying to do here. at first i assumed you were trying to count the number of characters but youre doing weird arithmetic with sum. either way, i think the cause of the infinite loop is that after the second while, though youre asking them to type a sentence, youre only scanning the first character which will never be a period unless you just enter a period. the loop only stops when the scanned character is a period so yeah infinite loop for anything other than a period.
    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.

  17. #17
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    Quote Originally Posted by God View Post
    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;
    }
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

  18. #18
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    You need to initialize checksum before using it to check a condition!

    ^ First thought. Reading the rest now.
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

  19. #19
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    Quote Originally Posted by God View Post
    while(sum != 46)
    {

    printf("Enter a one-line message. Complete your message with a period.\n");
    printf("Enter a message: ");

    while(checksum != SENTINEL)
    {
    scanf("%c", &checksum);
    sum += (int)checksum;
    }


    if(sum != 46)
    { check = sum % 64;

    finalcheck = (char)(check + 32);

    printf("Checksum: %c\n", finalcheck);
    }
    else
    printf("Program ended.\n");
    }

    }
    Does this not mean that when control comes out of the while loop, sum= 46? It's never going to enter the if condition then. What's 46 for, and can it be changed to while(sum<=46) or something.
    Last edited by trixie; 03-22-2012 at 02:07 AM. Reason: Indentation.... didn't work :(
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

  20. #20
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,491

    Default

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define SENTINEL '.'
    
    int main()
    {
    
        char checksum, finalcheck;
        int sum, check;
    
        sum = 0;
    
        while(sum != 46)
        {
    
            printf("Enter a one-line message. Complete your message with a period.\n");
            printf("Enter a message: ");
    
            while(checksum != SENTINEL)
            {
                scanf("%c", &checksum);
                sum += (int)checksum;
            }
            if(sum != 46)
            { 
                check = sum % 64;
    
                finalcheck = (char)(check + 32);
    
                printf("Checksum: %c\n", finalcheck);
            }
            else
                printf("Program ended.\n");
    
    
        }
    
        return(EXIT_SUCCESS);
    }

  21. #21
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    How did you do that, Rayne?
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

  22. #22
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,491

    Default

    [code] tags

  23. #23
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    Oh yeah, it didn't strike me because I've never used it
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

  24. #24
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,491

    Default

    i wasnt sure if vb had it. it was a shot in the dark.

  25. #25
    The One and Only trixie's Avatar
    Join Date
    Oct 2004
    Location
    In your dreams.
    Posts
    10,031

    Default

    Have you learnt any C yet?
    Originally made by LM:


    ~ I have said nothing because there is nothing I can say that would describe how I feel as perfectly as you deserve it. -- Kyle Schmidt ~

    ~Silence is one of the hardest arguments to refute. -- Josh Billings ~

    * dragon_berry**Fallen_Wings*

Page 1 of 3 123 LastLast

Posting Permissions

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