Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

fun fun C++

Name: Anonymous 2009-09-04 20:46

#include <stdlib.h>
#include <iostream>

using namespace std;

int main() { int number=rand()%100;
int guess=-1;
int trycount=0;
while(guess!=number && trycount<8) {
    cout<<"Please enter a guess: ";
    cin>>guess;
    if(guess<number) cout<<"Too low"<<endl;
    if(guess>number) cout<<"Too high"<<endl;
    trycount++;
    }
if(guess==number) cout<<"You guessed the number";
else cout<<"Sorry, the number was: "<<number;
return 0;
}

Name: Anonymous 2009-09-04 20:53

I see 3 problems with your post:
First, there was no code tags (can we get a sticky or something?)
Secondly, it was written in C++
and Thirdly, this trivial shit belongs in /pr/

Name: Anonymous 2009-09-04 20:58

>>2
There's more than 3.

Name: Anonymous 2009-09-04 21:13

>>2
Really, I didn't read the code. A passing glance was enough for me

Name: Haxus the C Cudder 2009-09-04 21:36

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

const int maxtries = 8;

int main()
{
    int number = (rand() % 100)+1;
    int guess=0, trycount=0;

    while (guess != number && trycount++ < 8)
    {
        printf("Enter a guess: ");
        scanf("%d", &guess);

        if (guess < number)  printf("\nToo low.\n");
        if (guess > number)  printf("\nToo high.\n");
    }

    if (guess == number)
        printf("\nYou win!\n");
    else
        printf("\nSorry, please play again.\n");

    return 0;
}

Name: Anonymous 2009-09-04 21:39

>>5
oops, I forgot to use the const I defined.

Name: Haxus the QBasic Cudder 2009-09-04 21:41

CONST MAXTRIES% = 8

number% = INT(RND * 100) + 1
guess% = 0
trycount% = 0

WHILE (guess% <> number% AND trycount% < MAXTRIES%)
    PRINT "Enter a guess: ";
    INPUT guess%

    IF guess% < number% THEN PRINT "Too low."
    IF guess% > number% THEN PRINT "Too high."
WEND

IF guess% = number% THEN PRINT "You win!"
ELSE PRINT "Sorry, please play again."

END

Name: Anonymous 2009-09-04 21:43

>>7
god damn, I keep forgetting shit.  Put this line before WEND:
trycount% = trycount% + 1

Name: Anonymous 2009-09-05 1:15

SUPERIOR


module Main where
import IO
import Monad
import Random

maxTries :: Int
maxTries = 8

loop :: Int -> Int -> IO Bool
loop number try = do
    if try < maxTries
        then do putStr "Enter a guess: "
                guess <- getLine >>= (return . read)
                when (guess < number) (putStrLn "Too low.")
                when (guess > number) (putStrLn "Too high.")
                if guess == number
                    then return True
                    else loop number (try + 1)
        else return False

main :: IO ()
main = do
    hSetBuffering stdout NoBuffering
    number <- randomRIO (1, 100)
    won <- loop number 0
    if won
        then putStrLn "You win!"
        else putStrLn "Sorry, please play again."

Name: Anonymous 2009-09-05 1:25

>>9
Haxus the...  I have no idea what language that is!

Name: Anonymous 2009-09-05 1:48

import Monad
Looks like perl to me!

Name: Anonymous 2009-09-05 1:48

>>9
VALID PERL CODE

Name: Anonymous 2009-09-05 1:49

>>11
>>12
Time Paradox!!

Name: Anonymous 2009-09-05 8:21

>>13
awsum

Name: Anonymous 2009-09-05 10:19

>>10
U MENA really shitty HASKAL

Name: UMH memesmith !qD.NH0oTGY 2009-09-05 12:30

>>15
God damnit, shut up!

Name: Anonymous 2011-02-04 12:42


Don't change these.
Name: Email:
Entire Thread Thread List