Computer Science Canada

"How Much You Suck" Program

Author:  S_Grimm [ Tue Apr 29, 2008 11:10 am ]
Post subject:  "How Much You Suck" Program

A friend of mine wanted me to make a program for him that determined how muck people "sucked". So I did. I'm looking for some constructive critisism on the program : namely, anything I could do to clean up the code. Oh, and only use lower case letters.

Author:  petree08 [ Tue Apr 29, 2008 11:37 am ]
Post subject:  RE:"How Much You Suck" Program

???

this is so bad...

there is no way a program that does this should be 139 lines

Author:  S_Grimm [ Tue Apr 29, 2008 11:49 am ]
Post subject:  Re: "How Much You Suck" Program

I ask for constructive critisism, not "This is so bad!". If I wanted that, I would have posted "Tell me how much this program sucks."

Author:  petree08 [ Tue Apr 29, 2008 12:10 pm ]
Post subject:  RE:"How Much You Suck" Program

well now that you invited the how does it suck...


- No input error checking
- no repetition
- unnessecary ifs
- the idea behind the program is terrible
- can't handle upper case
- at the begging promt "Do you want to play Enter yes or no" i typed in "dfgasdfa" and it just went on as if i entered yes
- program still runs even if "no" is entered
- i told it i have 0 letters in my name and it kept going, but then crashes
- "you suck 30%" ... um 30% of what?



There is almost nothing good i can say about this program

Author:  Sean [ Tue Apr 29, 2008 12:29 pm ]
Post subject:  Re: "How Much You Suck" Program

Turing:

%You suck program
%A\V


% Inizilizes
var yesno : string
var numberofletters : int


% Opening : if you wanna play
for opening : 1 .. 1
    put "This program will tell you how much YOU suck. Do you want to play?"
    put "Enter yes or no : " ..
    get yesno
    if (yesno = "no") then
        put "Well, if you want to play, come on back!"
        exit
    end if
    if (yesno = "yes") then
        put "Great. This game uses the number of letters in your name to determine how much "
        put "you really suck."
    end if
end for

% Getting the variables
for variables : 1 .. 1
    put "How many letters are in your name? : " ..
    get numberofletters
    put "Let me make sure I have this right. You have ", numberofletters, " in your name. Is this right?"
    loop
        put "Type 'yes' or 'no' and press 'Enter' : " ..
        get yesno
        if (yesno not= "no") and (yesno not= "yes") then
            put "Invalid Answer......"
        end if
        if (yesno = "no") then
            put "Please re-enter the number of letters in your name : " ..
            get numberofletters
        end if
        if (yesno = "yes") then
            put "Okay, let's move on."
            exit
        end if
    end loop
end for


There is no need for the for loops in the beginning of the program. These for loops are doing nothing, therefore are not needed.

Turing:

for i : 1 .. 1
%Stuff
end for


That does nothing, you start at 1 point and end at the same point. It is doing just one thing, and requires no for loop for those put statements.

Also, there is no need for the numerous if statements determining the the value fo the letters. You can combine these if statements into elsif statements and it will make the program cleaner then it is.

Some of your put statements need to be re-worded for users to understand.

Turing:

put "This program will tell you how much YOU suck. Do you want to play?"
    put "Enter yes or no : " ..
    get yesno
    if (yesno = "no") then
        put "Well, if you want to play, come on back!"
        exit
    end if
    if (yesno = "yes") then
        put "Great. This game uses the number of letters in your name to determine how much "
        put "you really suck."
    end if


Above, you have specified that the user needs to enter the number of letters in your name. With the previous question typing yes or no, the person is going to type the word for the number instead of the numerical value. That will result in the program finishing, I believe you should change it to accept what the user inputs. Both numerical and words.

Author:  btiffin [ Tue Apr 29, 2008 12:39 pm ]
Post subject:  Re: "How Much You Suck" Program

I'm not going to critique the code, but when doing funny/punny in your face programming like this; If the answer to the Do you want to play? is negative ... come on. "You Suck!" Is the response to that one. Smile

Cheers.

Author:  Tallguy [ Tue Apr 29, 2008 12:42 pm ]
Post subject:  RE:"How Much You Suck" Program

y do we suck due to the letters that make up your name?

Author:  S_Grimm [ Tue Apr 29, 2008 12:47 pm ]
Post subject:  Re: "How Much You Suck" Program

The idea was, yes you suck based on the LETTERS of your name, not the Number. and Petree, It's 30% of 100%. It's like a rating system.

Author:  petree08 [ Tue Apr 29, 2008 12:51 pm ]
Post subject:  RE:"How Much You Suck" Program

why would you even bother trying to defend this program? it's not even funny , just a waste of 139 lines

Author:  S_Grimm [ Tue Apr 29, 2008 12:55 pm ]
Post subject:  Re: "How Much You Suck" Program

Thanks y'all for the critism. I'll reprogram it with your suggestions.

Author:  raidercom [ Tue Apr 29, 2008 2:26 pm ]
Post subject:  Re: "How Much You Suck" Program

I might be tempted to do some input validation:
You can enter 1 for the number of letters in your name, then put 12 characters in.

Also, how come you can have a total suck rating of over 100%?

And someone else mentioned this, but the initial for loops are not needed.

I could be mistaken, but couldn't you use:
for a: 1.. length(input_variable)
for the for loop at the bottom? Instead of the weird array that you are using?

Author:  repsoccer16 [ Wed Apr 30, 2008 7:40 am ]
Post subject:  RE:"How Much You Suck" Program

petree you are supposed to be helpful not just critisizing his program and saying it sucks... help him improve don't discourage him.

Author:  Michael516 [ Wed Apr 30, 2008 7:41 am ]
Post subject:  RE:"How Much You Suck" Program

I don't think that you should bother fixing this program.

Author:  raidercom [ Wed Apr 30, 2008 9:53 am ]
Post subject:  Re: "How Much You Suck" Program

Michael516 wrote:

I don't think that you should bother fixing this program.

I don't think that this program should be fixed either, but he asked for help, and so I am giving him the critic that he asked for.

Author:  DarkFrogFTW [ Fri May 02, 2008 4:14 pm ]
Post subject:  RE:"How Much You Suck" Program

Is that an "Exit" statement in a for loop?
... A for loop that does everything inside once?

Fail. I know its mean, but even your program would agree that sucks 100% (I actually didn't ask it, but I'm assuming your program's logical here.)

It'd be a lot easier to make it a random amount. That makes about as much sense as basing it on the letters of their name, in my eyes.

4 lines, mate:

var Garbage: string
put "Enter your name!"
get Garbage
put "You Suck This amount: ", Rand.Int(0,100),"%"

and voila, a working "you suck" program.

Tell you what. If your going to spend 137 lines doing something, make it something useful, like a "zomg l33t halo game!" or something. As a general rule, if stupid programs like this take you over 20 lines of code to write, you fail epically.

Have a nice day.

Author:  Zampano [ Fri May 02, 2008 5:41 pm ]
Post subject:  Re: "How Much You Suck" Program

Quote:
Tell you what. If your going to spend 137 lines doing something, make it something useful, like a "zomg l33t halo game!" or something. As a general rule, if stupid programs like this take you over 20 lines of code to write, you fail epically.

Have a nice day.


What a superb post. I think that in those few sentences, I felt all of a dozen emotions I couldn't name. Rarely, if ever, does one see such an eloquent, yet succinct expression of disgust as did I see in your poetic post. I tell you, it takes a rare kind of genius to commit such immortal meaning to mortal language, the like of which has not been seen since the days of Henry David Thoreau.

Truly, you are a one destined for greatness.

Allow me, humble and unworthy peon that I am, to follow in your footsteps, as I would in those of King Wenceslas; the snow that impedes us in life is deep, and the wind sharp, but I know that at the degree of your resplendent skill and ingenuity, I shall not want.

Unwise as I am, and as you are such a big boy (no Pampers for this one!), I have but to ask: Please, DarkFrogFTW, be my leader.

Author:  jinjin [ Fri May 02, 2008 10:12 pm ]
Post subject:  Re: "How Much You Suck" Program

As was aforementioned, some of the for loops are unneeded or improperly executed. Therefore, I suggest you review the excellently detailed tutorial on loops and for loops by Cervantes here: http://compsci.ca/v3/viewtopic.php?t=3678. It will surely aid in making your code more efficient, thereby saving both yourself and the user time.

Furthermore, I would suggest that, at the ending of the program, another representation of how much the user "sucks" is run such as a picture, sound, or animation as the last output line simply stating a percentage is somehow ... anti-climatic.

As a simple side note, I would also recommend that, when you test this program (or any program for that matter), you should explore all of the different scenarios possible in terms of the user input in order to ensure that it runs smoothly and is completely error-free.

Regards,
jinjin

Author:  Clayton [ Fri May 02, 2008 10:58 pm ]
Post subject:  RE:"How Much You Suck" Program

The updated loops tutorial is found in the Turing Walkthrough.

Author:  DarkFrogFTW [ Sat May 03, 2008 1:18 pm ]
Post subject:  Re: "How Much You Suck" Program

Zampano @ Fri May 02, 2008 5:41 pm wrote:
Unwise as I am, and as you are such a big boy (no Pampers for this one!), I have but to ask: Please, DarkFrogFTW, be my leader.


Your Sarcasm bounces off my big, boyish exterior Razz. And come on, I thought I was being quite nice! I even wished him a nice day...

Anyways. To A/V. Out of curiosity, I wondered if I could get this program down to under the 20 lines I suggested was the "fail limit"... and I wasn't quite able to get it. With Input error checking, put statements for incorrect answers, converting to lowercase, and the cls, the total came up to 25. With all that stuff removed, though, it is exactly 20 (but perhaps there is better...). Note in both cases there is no blank lines or comments. So yeah, I failed, and you can rub it in all you like.

The biggest line killer was definately this:

const CharValues : array 1..26 of nat2 := init(bla bla bla..)
where "bla bla bla..." is the numbers you were assigning each letter, in "Alphabetical order", if that makes sense. like, if you had something like

code:
if YourString(Index) = "a" then
      total := total + 40
end if


then the number 40 would go into the first slot of the array, followed by a comma, then the value for b...

what this allows you to do is this:
code:
for Index : 1..StringLength
      total := total + CharValues(ord(YourString(Index))-96)
end for


"ord", if you didn't know, returns the ascii value of a character. If you made a simple program that put the ord val of a letter, you'd find "a" is 97, "b" is 98, and so on. so when I take 97 ("a") and subtract 96 from it, bam, I'm asking it for the value found in CharValues(1), which is 40.

This effectively turns your 78 lines of if structures into 4; 3 for the loop, 1 for the array.


: