Page 3 of 3 FirstFirst 123
Results 51 to 59 of 59

Thread: hey beagleman

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

    Default

    Quote Originally Posted by God View Post
    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. #52
    what about .. eyebrows God's Avatar
    Join Date
    Apr 2005
    Location
    among the people
    Posts
    49,754

    Default

    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. #53
    Registered Users Regular Rayne's Avatar
    Join Date
    Mar 2009
    Posts
    8,561

    Default

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

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

    Default

    Did you not get this example?

    Quote Originally Posted by Rayne View Post
    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. #55
    princeso Kirby's Avatar
    Join Date
    Mar 2009
    Posts
    19,023

    Default

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

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

    Default

    Quote Originally Posted by Rayne View Post
    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.
    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*

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

    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*

  8. #58
    Father Figure Qoorl's Avatar
    Join Date
    Nov 2007
    Location
    Pokedream
    Posts
    7,743

    Default

    Bah, You Nerds!
    JOIN AN RP YOU SLACKERS!

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

    Default

    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.
    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 3 of 3 FirstFirst 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
  •