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

Pages: 1-4041-

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.

Name: Anonymous 2009-06-12 12:34

assignment <- or -> (infix)
= should only be a comparison, not assignment

/THRAD

Name: Anonymous 2009-06-12 12:36

>>40
back to /b/ with you

Name: Anonymous 2009-06-12 12:38

>>40
I don't see any conflict of interest in both responding seriously and saging. In fact, from the way you are touting this everywhere when /prog/ is still trying to match the quality of our Japanese sister board, I think you would be best to head back to where you came from, namely, /g/.

Name: Anonymous 2009-06-12 12:40

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

Name: Anonymous 2009-06-12 12:41

•= only makes sense if is a binary operator, since
a •= b
stands for
a = a • b
Therefore != would be inconsistent with the rest of assignment operators, since a = a ! b doesn't make sense.
IHPBT,SNCBTS

Name: Anonymous 2009-06-12 12:43

>>44
I'll ask you again nicely. You only just arrived here and I think in retrospect we can all see it would be best for you to depart back where you came from. Thank you for your time.

Name: Anonymous 2009-06-12 12:44

And another thing, why don‘t **a and //a behave consistently with ++a and --a?  Fucking sepples.

Name: Anonymous 2009-06-12 12:44

>>45
NYJMUS

Name: Anonymous 2009-06-12 12:49

>>40
get out of here dumb dumb.

Name: Anonymous 2009-06-12 12:50

>>48
Shortcuts?

Name: Anonymous 2009-06-12 12:51

because **a is a pointer to a pointer to variable of type a.

And //a would signal comment line.

++ and -- are  used for increment and decrement in loops.

Name: Anonymous 2009-06-12 14:09

>>47
This is a good question. When you come down to it, the C family of languages is simply an ad hoc, grab-bag, random assortment of shift-characters masquerading as serious programming, with no internal consistency, context-sensitive grammar, and sad lack of referential transparency. It's one thing for English, Japanese, or !Kung to be all fucked up, they're natural languages that evolved over thousands of years, but programming languages are intentionally created by people. There's no excuse.

Name: Anonymous 2009-06-12 14:32

and a sad lack of referential transparency
C
a systems programming language
I lol'd

Name: Anonymous 2009-06-12 15:05

>>52
go back to bed

Name: >>47 2009-06-12 16:04

>>52
You see, I was actually pointing out what a worthless idea consistency is in this context.  Since it hinders expressiveness by adding bloat that no one has any use for.

Name: >>52 2009-06-12 17:01

>>55
WOW YOU DON'T SAY

Name: Anonymous 2009-06-13 5:48

It's me - Op again, thanks so much /prog/!

Btw >>22 wasn't me and >>23 is wrong.
But i guess i don't mind >>22 said he was me cause thanks to him >>24 pointed out what my mistake was.

I'm sorry i was so slow! I just now figured i needed to do "!="
instead of "!==" (thanks >>24).

Thanks alot /prog/ you win much!

Name: Anonymous 2009-06-14 1:10

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

int main(){

    int UPPER_LIMIT;
    int random;
    int userguess;
    char playAgain;
    random = rand()%20+1;

    do
    {
        userguess = 0;
        random = rand()%20+1;

        while(userguess != random)
        {

            cout << "Please enter a number between 1 - 20: ";
            cin >> userguess;

            if(userguess == random)
            {
                cout << "Wow, good job, you guessed right.\nDo you wish to play again? [ y / n ]: ";
                cin >> playAgain;
                cin.get();
            }

            else if(userguess > random)
            {
                cout << "That number is too high." << endl;
                cin.get();
            }

            else if(userguess < random)
            {
                cout << "That number is too low." << endl;
                cin.get();
            }
        }

    } while( playAgain == 'y' );
}
</code>

fix'd

Name: Anonymous 2009-06-14 1:27

ITT sepplesfags prove that they're too stupid to understand simple [b][i][o][u]BBCODE[/u][/o][/i][/b].

Name: Anonymous 2009-06-14 1:45

Dear OP, I fixed you're code.

"dagame" < aðal {
aðal -> stef(;)
    staðvær goal, guess, left := 10
    stofn
        goal := slembi(;) % 1000 + 1,
        lykkja
            \skrifafjöl left,
            \skrifastreng " guesses left\nGuess: ",
            guess := lesa(;),
            ef ekki \ertala guess þá
                \skrifastreng "wat\n"
            annarsef guess < goal þá
                \skrifastreng "Too low\n",
                left := left - 1
            annarsef guess > goal þá
                \skrifastreng "Too high\n",
                left := left - 1
            annars
                \skrifastreng "You won!\n",
                út
            eflok,
            ef left <= 0 þá
                \skrifastreng "You lost ;(\n",
                út
            eflok
        lykkjulok
    stofnlok
}
*
!{
slembi -> stef(;)
    innflutt sædi
    stofn
        ef ekki sædi þá
            sædislembi(;)
        eflok,
        sædi := sædi * 649 + 1801 + sædi / 1023
    stofnlok

sædislembi -> stef(;)
    innflutt sædi
    staðvær k,m,s,i
    stofn
        sækjatíma(k,m,s;),
        sædi := k*3600 + m*60 + s,
        fyrir(i := 0; i < 10; i := i+1) lykkja
            slembi(;)
        lykkjulok
    stofnlok
}
*
{ sædi -> breyta }
*
"GRUNNUR"
;

Name: Anonymous 2009-06-14 2:30

>> 28
/=

Name: Anonymous 2009-06-14 15:13

>>60
I should really finish my Fjölnir interpreter. It could do most of that simple program‚ it❜s just missing a lot of "GRUNNUR" functions and the whole linking of modules thing. (Also innútbreyta.)

Are you using Snorri Agnarsson's compiler‚ or one of your own devising?

Name: Anonymous 2009-06-14 18:44

>>62
I‘m using FJOLNIR2.EXE for now.  I‘f been planning to make my own compiler (an LLVM frontend), but all I have written is the parser.  I was going to post it on /prog.git/ once it could dump a syntax tree.  I‘m quite INEXPERT at compilers though, so working out code generation will probably be harder than deciphering the docs.

Also, I‘m sad that nobody acknowledged http://dis.4chan.org/read/prog/1244233849/18.  Please take a look at it if you have time.

Name: Anonymous 2009-06-14 19:30

>>63
I acknowledge http://dis.4chan.org/read/prog/1244233849/18. Please be less sad now.

Name: Anonymous 2009-06-14 19:40

>>63
I saw it when you posted it, and I was quite impressed; I guess I didn‘t respond though. Probably because I don‘t have a 32-bit windows box to run it on, and I suspect it wouldn‘t run under wine. I can more-or-less see what it‘s doing, though.

Well, I guess I should post mine somewhere, since it can dump a syntax tree. It‘s written in dead dog¹, is disgusting in a porcine fashion, and generates a 5MB executable², but it works.

Have a look at http://filebin.ca/xvfkdb/fjolnir.tar.gz if you‘re bored and understand Haskell. I've only implemented the parts of "GRUNNUR" that I've been interested in so far, which isn't a great deal.

¹ ;_;.
² Then again, most Haskell programs does this.

$ ./Main
"GRUNNUR"> 1+2+3+4+5+6
(((((1 + 2) + 3) + 4) + 5) + 6)
21
"GRUNNUR"> \hali \haus \haus [1,2,3,4,5,6]
(\hali (\haus (\haus [1,2,3,4,5,6])))
Desugared: (\hali (\haus (\haus (1 : (2 : (3 : (4 : (5 : (6 : [])))))))))
----
3
"GRUNNUR"> fyrir(x := 1, y := 0; x <= 10; x := \stækka x) lykkja y := y + x lykkjulok
fyrir((x := 1),(y := 0);(x <= 10);(x := (\stækka x)))  lykkja (y := (y + x)) lykkjulok
55
"GRUNNUR">█

Name: Anonymous 2009-06-14 23:09

>>65
I saw it when you posted it, and I was quite impressed; I guess I didn‘t respond though. Probably because I don‘t have a 32-bit windows box to run it on, and I suspect it wouldn‘t run under wine. I can more-or-less see what it‘s doing, though.
:)
Here, have a screenshot: http://i42.tinypic.com/2csj910.jpg
The data is the number of pixels to run before each color switch, and most of the actual code deals with stuffing pixels into the right bit positions on a black-and-white bitmapped display (necessary to get that kind of resolution in 16-bit DOS).

Have a look at http://filebin.ca/xvfkdb/fjolnir.tar.gz if you‘re bored and understand Haskell. I've only implemented the parts of "GRUNNUR" that I've been interested in so far, which isn't a great deal.
This is way beyond my Haskell ability, but I‘ll definitely look it over.

Name: Anonymous 2009-06-15 12:27

>>66
http://i42.tinypic.com/2csj910.jpg
I "GRUNNUR"'d.

Apparently I got \hali and \haus the wrong way round when I actually added them to my code. Oops. There's probably a lot of things like that.

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