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

C++

Name: Anonymous 2009-06-12 6:31

Hello /prog/.

I know very little about C++. and my only other experience with programming is a calculator in freeBasic.

I studied how to programm a guessing game from the internets but my 4.9.9.2 Dev C++ fail to compile it.

this is what i wrote:

#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;

int main(void){
   
    int UPPER_LIMIT;
    int random;
    int userguess;
    char playAgain;
    srand(static_cast<unsigned int>(time(0)));
    random = rand()%20+1;
   
    do{
                           
    while(userguess !== random){
   
    cout << "Please enter a number between 1 - 20: ";
    cin >> userguess
   
    if(userguess == random){
                 cout << "wow good job you guessed right." <<endl;
                 }
                
    else if(userguess > random){
    cout << "that number is too low" <<endl;
    system("CLS");
}
        
    else if(userguess < random){
         cout << "that number is too high" <<endl;
    system("CLS");
   
    }
}

cout << "Do you wish to play again? y//n: ";
cin >> playAgain;


} while(tolower(playAgain == 'y');


getch();
return 0;
}

PLEEAASE HAAALP /PROG/.
Thanks in advance.

Name: Anonymous 2009-06-12 6:38

Do your own homework

Name: Anonymous 2009-06-12 6:39

I dont like the way you're expressing your help request, Anonymous

Name: Anonymous 2009-06-12 6:42

Please use [code] tags.

Name: Anonymous 2009-06-12 6:48

#include <conio.h>
I lol'd. Twice. 3/10

Name: Anonymous 2009-06-12 6:56

What the hell does conio stand for?

Name: Anonymous 2009-06-12 6:57

>>5
Hey, I always included conio.h when I started programming too, because I didn't know anything and that's what was used in the tutorials I read.

>>1
To get any help you must repost this using [code] tags and Allman-style bracket placement.

Name: Anonymous 2009-06-12 7:03

>>1
Also because I'm nice, you left out a semicolon after cin >> userguess.

I just realized that while using the same identifier, Haskell's >> is much better than C++'s >>.

Name: Anonymous 2009-06-12 7:03

I lolled so hard I grabbed my dick!

Name: Anonymous 2009-06-12 7:05

>>7
[code] tags and Allman-style bracket placement.
Holy crap are you me?

Name: Anonymous 2009-06-12 7:24

>>7
Because you didn't know how to use scanf? Did you read a fucking microsoft users manual?

Name: Anonymous 2009-06-12 7:33

Op here.
Sorry >>3 and >>4.
It isn't my homework i learn it for fun >>2.
Thanks >>7 and >>8 but it still fails to compile it.
I'll try to repost it using [code] tags (now after i fixed the semicolon) :

[code]
#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;

int main(void){
   
    int UPPER_LIMIT;
    int random;
    int userguess;
    char playAgain;
    srand(static_cast<unsigned int>(time(0)));
    random = rand()%20+1;
   
    do{
                           
    while(userguess !== random){
   
    cout << "Please enter a number between 1 - 20: ";
    cin >> userguess;
   
    if(userguess == random){
                 cout << "wow good job you guessed right." <<endl;
                 }
                
    else if(userguess > random){
    cout << "that number is too low" <<endl;
    system("CLS");
}
        
    else if(userguess < random){
         cout << "that number is too high" <<endl;
    system("CLS");
   
    }
}

cout << "Do you wish to play again? y//n: ";
cin >> playAgain;


} while(tolower(playAgain == 'y');


getch();
return 0;
}
[code]

Am i doing it right now?

Name: Anonymous 2009-06-12 7:40

>>10
No, we're just both sane.

>>11
No, because I was about 14 and I just wanted to make games, so I found a tutorial about game programming in C++, and at the time I couldn't care less about what I was using as long as I'd learn programming.

Name: Anonymous 2009-06-12 7:41

>>12

maybe learn htnl first

Name: Anonymous 2009-06-12 7:46

>>12
The proper usage is [code]code here[/code]

Why don't you use the compiler's output to determine what's wrong? I'm sure it gives you helpful messages including the line number at which it finds an error.
I found another obvious mistake, but this time try to find it yourself.

Name: Anonymous 2009-06-12 7:51

>>12
I found two syntax errors, actually.
Also you don't need to escape /, if that was what you wanted to do in "Do you wish to play again? y//n: ".
And what kind of editor are you using?

Name: Anonymous 2009-06-12 8:21

3rd attempt to repost with tags:

[code]
#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;

int main(void){
   
    int UPPER_LIMIT;
    int random;
    int userguess;
    char playAgain;
    srand(static_cast<unsigned int>(time(0)));
    random = rand()%20+1;
   
    do{
                           
    while(userguess !== random){
   
    cout << "Please enter a number between 1 - 20: ";
    cin >> userguess;
   
    if(userguess == random){
                 cout << "wow good job you guessed right." <<endl;
                 }
                
    else if(userguess > random){
    cout << "that number is too low" <<endl;
    system("CLS");
}
        
    else if(userguess < random){
         cout << "that number is too high" <<endl;
    system("CLS");
   
    }
}

cout << "Do you wish to play again? y//n: ";
cin >> playAgain;


} while(tolower(playAgain == 'y');


getch();
return 0;
}



Thanks >>15, i hope i did it right this time. Also i don't have line numbers and i don't understand the compiler's output:
"in function 'int main()':
 line 17 - expected primary-expression before '=' token
 line 42 - expected ')' before ';' token"

Hey wait a second.. Now that i look at it i really did forgot a bracket in line 42. You were right >>15.. But this one output was simple to understand, what does the 2 other lines means?

>>16 Is BloodShed or mingw32 editors? If not i'm not sure what editor it is, sorry.

Name: Anonymous 2009-06-12 9:23

!==
This is not PHP. If you really can't figure this out I'm going to have to ask you to go [i]back to /preschool/ please.

Name: Anonymous 2009-06-12 9:23

>>17
Why don't your try to figure out what
 line 17 - expected primary-expression before '=' token
 line 42 - expected ')' before ';' token"

means?

Name: Anonymous 2009-06-12 9:39

>>18 Op here. Shoul i nt write "!=="? What should i write instead?
>>19 read all of post >>17 in the end i said i figured the bracket missing in line 42 but the other output of the compiler were not understandable for me, what do they mean?

Name: Anonymous 2009-06-12 9:39

>>20
<> or <=> dependening

Name: Anonymous 2009-06-12 9:39

>>21 Op here. dentending on waht?? id on't GET IT?!!

Name: Anonymous 2009-06-12 9:43

ITT: OP trolls you all

Name: Anonymous 2009-06-12 9:45

>>22
YHBT, it should be !=
This thread was exactly the pick-me-up I needed this morning :)

Name: Anonymous 2009-06-12 10:03

Now that I think about it, !== makes much more sense than !=, which should be more like bitwise negation and assignment, given operators like += and *=.

Yet another example of why sepples sucks so fucking much.

Name: Anonymous 2009-06-12 10:35

>>25
All you have said applies to C, Java, Javascript as well. What now faggot. YHBT.

Name: Anonymous 2009-06-12 10:38

>>26
Those all suck ass, too.

Name: Anonymous 2009-06-12 10:49

>>25
Is bitwise negation a task you do often enough, that you think it deserves an operator?
The reason we use !== instead of != is the same reason we use cd/rm/cp instead of changedir/remove/copy, it saves some marginal amount of typing and screen space back when it was more of an issue. Some people advocate <>, but I don't think it works particularly well for non-numbers.

Name: Anonymous 2009-06-12 10:53

Is bitwise negation a task you do often enough, that you think it deserves an operator?
No. It is not a questions of whether it is done often enough. There are hosts of operators standard in C/C++ that don't get used often. It is a question of a consistent interpretation of symbols, rather than an ad hoc implementation.

The reason we use !== instead of != is the same reason we use cd/rm/cp instead of changedir/remove/copy, it saves some marginal amount of typing and screen space back when it was more of an issue.

Code is read more than it is written. This excuse has never made sense.

Name: Anonymous 2009-06-12 10:56

>>29
Use Applescript then

Name: Anonymous 2009-06-12 11:00

>>17
If not i'm not sure what editor it is, sorry.>>17
Had me until there.

>>25
! is a fucking unary operator. It would make no sense to combine it with assignment.

Name: Anonymous 2009-06-12 11:25

>>31
! is a fucking unary operator. It would make no sense to combine it with assignment.

a = !b
a != b

HURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR

Name: Anonymous 2009-06-12 11:28

a = !b
a != b

That's just stupid, the first is infinitely more readable.

Name: Anonymous 2009-06-12 11:30

>>33
It is inconsistent with other x= symbols which combine an operation and assignemnt. This is the beef. Please keep up.

Name: Anonymous 2009-06-12 11:46

>>34
OK then, shouldn't it just be "b != " then? Having "a != b" is likewise inconsistent.

Name: !MILKRIBS4k 2009-06-12 11:47

C is superior to C++!

Name: Anonymous 2009-06-12 11:49

echo >>35 | sed 's/then//2'

Name: Anonymous 2009-06-12 11:57

>>33
The first is also infinitely incorrect. a = !b implies equality of a with b's complement, which is only a one way guarantee of inequality. Really it should be, a ⊃ (a ∩ b).

Name: Anonymous 2009-06-12 12:00

>>38
Good luck convincing keyboard manufacturers.

Name: Anonymous 2009-06-12 12:29

>>37
>>38
don't sage if you're replying to the thread. sage if you are saying 'fuck this thread, go to /r/' or whatever. idiot.

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