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

Pages: 1-4041-

cin skipping

Name: Anonymous 2008-03-08 7:18

Well, I was bored and decided to make up a quick game in C++ and at the same time try to use all the new shit I need to learn like classes and such and incorporate it into the program. But one of the simplest errors is occuring. Everytime it hits a certain cin.getline it will skip it and continue without pausing for input. I've tried cin.ignore, cin.clear, blah blah but they all don't work for me... o_O
Anyway code for people to look at... It's probably not good but oh well.



#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
#include <windows.h>
using namespace std;

class words {
public:
    words();
    void getWord();
    void greeting();
    void initFS();
    void fileWrite();
private:
    int i;
    int a;
    int time;
    int numChars;
    char word[102];
    char name[30];
    string strungWord;
};

void words::getWord() {
    cout << "Please enter the word you would like to use: ";
    while(a==1) {
// This is the part being skipped ----> cin.getline(word, 101);
    for(i=1;i<3;i++) {
        if(word[i] == '\0') {
            cout << "That word is too short. Please type a longer one.\n";
            a = 1;
            break;
        }
        a = 0;
    }
    }
}

void words::initFS() {
    a = 0;
    cout << "Would you like to play in Fullscreen mode? (y/n)\n";
    while(a==0) {
    cin >> strungWord;
    if(strungWord == "y") {
        a = 1;
    }
    else if(strungWord == "n") {
        a = 2;
    }
    else cout << "\"y\" or \"n\" was not entered. Please enter \"y\" or \"n\".\n";
    }
    if(a==1) {
        keybd_event(VK_MENU, 0x38, 0, 0);
        keybd_event(VK_RETURN, 0x1c, 0, 0);
        keybd_event(VK_RETURN, 0x1c, KEYEVENTF_KEYUP, 0);
        keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 0);
    }
    cin.clear();
    system("CLS");
}

void words::greeting() {
    printf("Welcome to the \"Speed Typing\" game.\n"
        "In this game you try to type a word as quickly as possible under a certain time limit.\n"
        "Press any key when you are ready to begin.\n");
    system("PAUSE");
    system("CLS");
}

void words::fileWrite() {
    cout << "Please enter your name for the scores record: ";
            cin.clear();
            cin.ignore(29, '\n');
            cin.getline(name,29);
            ofstream writeto("Scores Record.txt", ios::app);
            if(a==1) {
            writeto << endl << name << " beat level " << (i-1) << " with the word \"" << word << "\".";
            }
            else if(a==0) {
            writeto << endl << name << " beat level " << (i) << " with the word \"" << word << "\".";
            }
            system("PAUSE");
}

words::words() {
    time = 10;
    initFS();
    greeting();
    getWord();
    for(i=1;i<11;i++) {
        cout <<"Prepare for level " << i << "..." << endl;
        system("PAUSE");
        cout << endl << "Go! Type in your word in less than " << time << " seconds!\n";
        clock_t start_time;
        start_time = clock();
        cin >> strungWord;
        if((clock() - start_time) > time * CLOCKS_PER_SEC) {
            cout <<"Sorry, you didn't type the word quickly enough. You lose.\n";
            a = 1;
            fileWrite();
            i = 11;
            break;
        }
        else if(strungWord != word) {
            cout << "Sorry, you didn't type the word correctly. You lose.\n";
            a = 1;
            fileWrite();
            i = 11;
            break;
        }
        else if(strungWord == word && (clock() - start_time) < time * CLOCKS_PER_SEC && i < 10) {
            cout << "Congratulations, you progress to the next level.\n";
            system("PAUSE");
            system("CLS");
        }
        else if(strungWord == word && (clock() - start_time) < time * CLOCKS_PER_SEC && i == 10) {
            cout << "Congratulations!! You've won the game by beating all levels!\n";
            for(numChars=0;numChars<101;numChars++) {
                if(word[numChars] == '\0') {
                    break;
                }
            }
            cout << "Your word was " << numChars << " characters long!\n";
            a = 0;
            fileWrite();
            i = 11;
            break;
        }
        time--;
    }
}

int main() {
    words::words();
    return 0;
}




In before "DON'T HELP HIM".

Name: Anonymous 2008-03-08 7:25

Too long; I didn't read it. Text book case of using the extraction operator (>>) before calling the getline method. >> leaves the newline in the buffer, getline consumes it and thus doesn't pause for input. Everywhere where you've used >>, use a cin.ignore() straight after it.

Name: Anonymous 2008-03-08 7:29

>>2

I've done that, as stated in my opening paragraph, and it doesn't work. I've tried it twice in a row even. I don't know why it doesn't, but cin.ignore is not working.

Name: Anonymous 2008-03-08 8:04

SCANF IS SUPERIOR

Name: Anonymous 2008-03-08 9:08

Cin is a faggot

Name: Anonymous 2008-03-08 10:29

Short answer: Do not use >>, ever. Problem solved.

Name: Anonymous 2008-03-08 21:26

>>6

Tried it, still is skipping

Name: Anonymous 2008-03-08 21:40

>>7
Then you just suck, how do you like that answer huh? Fucking sepples noob

Name: Anonymous 2008-03-08 21:50

>>8

It doesn't answer my question, so I don't really like that answer, no.

Name: Anonymous 2008-03-08 22:25

>>7
You're still using >>.

Name: Anonymous 2008-03-08 22:31

>>4

Name: Anonymous 2008-03-08 22:46

>>10
No, no.

I rewrote the code and replaced all >> with getlines and such. The certain getline is still skipping.

I even deleted every other cin in the code except for the one that is skipping, and it still continues to skip.

Name: Anonymous 2008-03-08 23:00

Have you run it through a debugger and set it to break where the cin skips? If it doesn't break at that line, it's probably because of a logic error on your part.

Name: Anonymous 2008-03-09 4:35

>>12
Maybe you should take away her skipping rope.

Name: Anonymous 2008-03-09 5:38

Question:
What does :: do in Sepples?

Name: Anonymous 2008-03-09 5:57

Question:
What does -> do in Sepples?

Name: Anonymous 2008-03-09 6:18

Question:
What does <- do in Sepples?

Name: Anonymous 2008-03-09 6:22

getline15

AMI DOIN IT RITE?

Name: Anonymous 2008-03-09 6:25

>>15-17
Same nomad and we have been trolled constantly.

Name: Anonymous 2008-03-09 6:26

Question:
What does :: do in Haskell?
What does -> do in Haskell?
What does <- do in Haskell?

Name: Anonymous 2008-03-09 6:32

>>20
:: denotes type signatures
-> shows type transitions in function signatures (e.g. Int -> [Char] takes a small integer and returns a string)
<- temporarily assigns the results of executing the action on the right to the variable to the left (e.g. text <- getLine).

Now please answer the Sepples question.

Name: Anonymous 2008-03-09 6:57

>>21
:: is the scope operator, -> selects an element through a pointer and <- checks if the left hand argument is less than the negative of the right hand argument.

Name: Anonymous 2008-03-09 7:04

>>22
bullshit, no <- operator in sepples, consider this example a<-b+c; not the same as a<-(b+c) you described

Name: Anonymous 2008-03-09 7:12

>>21
:: denotes type signatures
Correct.

-> shows type transitions in function signatures (e.g. Int -> [Char] takes a small integer and returns a string)
More formally, it is the type constructor for functions. It takes as parameters two type constructors of any kind, the first being the type the function expects as input, and the second being the result type (which may, of course, be another application of (→) to any two type constructors – this is why we can have so-called multi-parameter functions).

Also, in a lambda or a case, ``→'' is the delimiter between a pattern and the corresponding expression.

<- temporarily assigns the results of executing the action on the right to the variable to the left (e.g. text <- getLine).
That is how you think of it in imperative terms, but in actuality it is just syntactic sugar for binding (>>=) the expression on the right to a lambda with the pattern on the left, whose function body is the rest of the do-block. E.g.:

do
  pat ← a
  b


is desugared to:

a >>= λ pat → b

This also happens to be the reason why you cannot end a do-block with one of these ``assignments''.

Name: Anonymous 2008-03-09 7:54

Question:
What does -- do in Haskell?
What does >- do in Haskell?
What does -< do in Haskell?

Name: Anonymous 2008-03-09 8:29

Question:
What does <=> do in Haskell?

Name: Anonymous 2008-03-09 8:49

Question:
What does cdr do in LISP?

Name: Anonymous 2008-03-09 8:55

>>27
Access the content of the decrement register.

Name: Anonymous 2008-03-09 8:56

>>28
of a cons data structure

Name: Anonymous 2008-03-09 9:41

>>25
-- is one-line the comment delimiter

Name: Anonymous 2008-03-09 10:03

Question:
What does BEGIN do in Pascal?

Name: Anonymous 2008-03-09 10:26

Question:
What does k do in Befunge-98?

Name: Anonymous 2008-03-09 10:42

>>32
nothing.

Name: Anonymous 2008-03-09 10:42

>>25
-< feeds the value of an expression into an arrow.

Name: Anonymous 2008-03-09 10:48

>>1
Some  of  your functions have branch cuts, across
       which the function is  discontinuous.   For  implementations
       with a signed zero (including all IEC 60559 implementations)
       that follow the specification of annex G, the sign  of  zero
       distinguishes one side of a cut from another so the function
       is continuous (except for format limitations) as the cut  is
       approached  from  either  side.  For example, for the square
       root function, which has a branch  cut  along  the  negative
       real  axis, the top of the cut, with imaginary part +0, maps
       to the positive imaginary axis, and the bottom of  the  cut,
       with imaginary part -0, maps to the negative imaginary axis.
So what this means, OP, is that you should stick to VB.

Name: Anonymous 2008-03-09 16:07

Question:
What does nop do in Intel x86 Assembly?

Name: Anonymous 2008-03-09 16:09

>>36

It has something to do with sliding down a mountain.

Name: Anonymous 2008-03-09 16:18

>>36
It allows you to exploit a buffer overflow.

Name: Anonymous 2008-03-09 16:18

>>1
decided to make up a quick game in C++
Found your problem.

Name: Anonymous 2008-03-09 16:24

>>39
Sepples

Name: Anonymous 2008-03-09 16:40

My favourite lines
else cout << "\"y\" or \"n\" was not entered. Please enter \"y\" or \"n\".\n";
words::words();

Also, it's skipping
// This is the part being skipped ----> cin.getline(word, 101);
because you commented it out, asshole.

Name: Anonymous 2008-03-09 17:07

>>41

Naturally I expected to have my code made fun of. I'm only just scraping the surface of C++.

And I only commented out when I typed it into /prog/, so that people may see the area being skipped. I guess I could have commented out the line before it and left the actual skipping part without commenting it out, but I thought the smart people of /prog/ would see it and figure they needed to take out the "// This is the part being skipped ---->".

Name: Anonymous 2008-03-09 17:37

>>42
when I typed it into /prog/
Now you have two problems.

Name: Anonymous 2008-03-09 17:40

cat myProgram.cpp |/prog/

Name: Anonymous 2008-03-09 18:01

>>44
I'm going to write a /dev/prog device (read it as ``DPD prog device'') that you can pipe to to create new threads in /prog/.

Not.

Name: Anonymous 2008-03-09 18:17

>>45
Do it, or don't post about it.
Kike.

Name: Anonymous 2008-03-09 18:29

>>45
Do it under [spoiler]GNU/HURD[spoiler].

Name: Anonymous 2008-03-09 18:29

I meant to do that

Name: Anonymous 2008-03-09 21:15

>>45
cat /dev/random > /dev/b

Name: Anonymous 2008-03-09 21:20

>>45
Enjoy getting banned whilst testing it.

Name: Anonymous 2008-03-10 3:54

>>50
That's why I won't do it :/

Name: Anonymous 2008-03-10 4:14

Would it be considered cheating to create a prog demon and tyya/ptya (or ptmx) pair?

Name: Anonymous 2008-03-10 6:04

>>50
7 proxies bitches

Name: Anonymous 2008-03-12 17:19


∵∴                ___∵∴ ___
∵∴`.__           ,-' ∵∴∵  ,-.`-,
∵∴∵∵∴∵∴∵∴∵∴∵∴∵∴ ( p )  ._
∵∴∵∴∵∴∵∴∵∴∵∴∵∴∵∴`-'∵∴ (
∵∴∵∴∵∴∵∴∵∴∵∴∵∴∵∴∵∴∵∴ \
∵∴∵∴satori∵∴∵∴∵∴∵∴.∵∴∵∴∵\
∵∴∵∴∵∴∵∴∵∴∵∴∵∴   \---..,--'
∵∴∵∴∵∴∵∴∵∴_  ∵∴∵   --...--,
                     ∵∴- ∵∴∵ _.-'
                          ∵∴-''

Name: Anonymous 2008-03-12 17:51


jjj++::+jj+jjj+++++:::+:j+:::::::::++++jj66666j+6bbbbHMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMH+
+ j6j+::+:+jjj+++j+++:::::+jjjj++++++jjj++:++++6j++b6jjMMMMMMMMMMMMMMMMMMMMMMMMMMMMMH+
+ j+:6j+++++::jjj66j+++++++jjj6++++++66jj++jjj++:jj++++jbHMMMMMMMMMMMMMMMMMMMMMMMMMMH+
+ +++j+++++jj++++:++jjjj+++j++j++++++b66j:::::::::::jj++jj6HMMMbHMMMMMMMMMMMMMMMMMMMH+
+ +++j+++++j++jjjj+++++jj++++++++++++++::.:.:..:.......::++jjHM6HMMMMMMMMMMMMMMMMMMHj:
: +j+j+++++j++++jj++jj++++++++++++:::.:......................++jjMMMMMMMMMMMMMMMMMMM+:
: +:+jj+++jj++++jj+++jjjjj+jj+j+:::.:....:.....................++6MMMMMMMMMMMMMMMMM6+
: ::+j6+++++j+j+jj+++6j+++j6j++::................................:+bHMMMMMMMMMMMMMMH.:
+ +j+j+++++++jjj6j+++6j+++j6+:::...................................:+6MMMMM6jMMMMMM+:
+ :+++++++++jjj6j+++jjjjj++++::::::::::...:..........................:jjbMH6bMHMMMMM+:
+ :+j++++++++:jj6j++++jjj+++:::::+++++++:::.::.......................:+j66bHbb6HbMMM+:
: +j+::++j++++j+++::+6++++::::+6bbbHHbb6bb6b6++:::::::................:j66HbHbb6666H+:
+ ++jjjjj6+:++jj+++++++++:.:jbHHHMMMMHHMMMHHbbb6jjjjjj+:::::............:+++++jbb6bb++
+ ++j+j++jjjjj66:++j+++j:::jbHHHMMMMMMMMMMMMMMHHHHHHbb+j+::..............+666+++j6bH++
: :jjjj+:+jj6666jj66j+jj+.+6bHHHHMMMMMMMMMMMMMMMMMMHHHbb6j:::..::.:......jbbb66j::++++
+ :+jj6+++jj6666jjjjjjjj::+6HHHMMMMMMMMMMMMMMMMMMMMMMHHHbj+::::::::.:.:.:6bbbbb6j++::+
6 bbbHHHHHHHHHHHbbb6jjjj::+6HHHMMMMMMMMMMMMMMMMMMMMMMHHHHb+::::::.::::::+bbbbbbb6jjj++
: :::::::::::+++j66bbHHb+.j6bHHHMMMMMMMMMMMMMMMMMMMMMMHHHbb+:::::..:.:::+6bbbbb6j66j+6
: ::::::::::::::::::::6H+.+++jjbbHHHHMMMMMMMMMMMMHHHHHHHHHbb6+:::.::::::+b6j666jjj6666
: ::::::::::::::::..::6Hj:::++:+::+6bHHHHb66jj++jjj6666bbHHHb6::::::::+jjbb6j++jj+++++
: ::::::::::::::::..:+j+++++jjj+jjjj6bHMH66jjjjjjj66b6j6bbbbbj:::::6bHb6bbbb6+::::::.:
. ....:.:..:.:..:::::::+:+:+++j+:+6j:66bj6bb6666+++j666jj+:::jj:::+6bHHbHbbb6+++:.:...
. .:.........:.:::::::jjjj+j6j666bbj+HHMb+jbHb6b66666666bbbbbb6+::jbHHHHHbbb6++++::...
: ::..::::::::::.:::::bbj+66bbbbbbb6bHMHHb6bHHHHHHHHHHHHHHHHbbb+:+bHHMHH66666j+j:+:+:+
: ::...::::::::::::::+bb6j6bHbbbHHHbbHMHHbHHHHHHHHHHMMMMMHHHHbbj+jHHHHHb666bjjjjj+jj6j
: :..::::.:::::::::::+b6jjjbHHHHHHHHHHHHHbbbbHMMMMMMMMMMMHHHbb6++jHHHbj+++++::::::.:+:
+ jjjjjjjj++++++:::::+6j+++6HHHHHHHbHHHHHHbbbHHHMMMMMMMMHHHbbb6++jb6jj6j++:::::::++:::
: :+jj666jjjjjjjjjj+:jj+j6++6bbHHHHb6bb666b6bHHHHMMMMMMHHHHbb6j::::::::::::::::::j++::
: :::jbbbbbbb6666jj+:+jj66jjjbbHbHHH66bbbbbHHHHHHHHHHHHHHHHbb6+:::::::::::.::::::j+:::
: ::::+66bbbbb66bbbj:j6j++j++bHb66b6+j6b6jj6bbHbbbbbHHHHHHb66j+::::::::++::::.:.+j+:::
: :.:::++jjjjjjjbbbHb6b6+66++66j++j6+jj6b6jj6j6jjj666bHHHbb66j+:::::::+j+:::::.:+6+:.:
: :::::.:jjjjjjjbbHbbb666bjj+++j6bbb6bbbbbHHbbbHHHHHbbb666b6j+::+j:..:jjj6::::::+6::::
: :::::::+j++jj6bbbbbbb6j+j66+++jbbHbbbbbbbbHHHMHHHHbbb6666j+:+j+:+++.:+::::::::jj::::
: ::::::::jjjjj66bbbbbbbjjjjj+:++j6HHHbHHHHHHHHHHH66666666+::+6b6:::::::::++::::jj::::
: ::::::::jjjjbb+::::jb66j66jj++:++6HHHHHHHHHHbb66jjjjj++::++6Hbb:::.:::::+j::::jj::::
: :::..:.+jjj6bb+::::jb6jjjjj++::+++6bbb6jjb666j++++:++:::+66HHbb+::::::::::::::jj::::
: :::..:.jjjjbb6+::::6b6j+::::::::::+j+:++++++++++:::::::+6HHHHHbj::::::::::::.:jj::::
: :::..::+jjjbbb+::::6b6j+:..::::::::+::::::::::::::::::+6HHMHHHb+:::.::::::j6+:j+::::
: ..:..::.+66bb6+:::::::::::.:.:.:.:::.:.:.:::.::.::::j6HHMMMMHHH::::..:::.:jj++j+::+:
: ..:..:::::::::.:.:::.:.....:..:::.:.:...:.::::::::j6HHMMMMHHHHb::.::...::::::+j+:+::
. :........:.:::::.:.:.:::.....:.::::jj6j66j+++j66bHHHMMMHHMHHHbj::.::..::.::::.:::+::
. :...:.:....:.::::.:::.:..:.:.:.:::++j6bHHHHbbbHHHHHHHMHMMMHHMj:::.:::.:..:::..::::::
. ............:...:::.:..:..:.:...:++++++++j6bbHHHHHMMMMMMMMMM6::.::.:.:.:..:.::.:..::
. ..............:..:.:..:....:.:...::.:+++++++++++jjjjjjjjjj6+:::.:..:::::..:..:....::
. .........:.:..:..:.......:...:.:+++:++:+++++++++++++jj++++j::...:..:::..::.::.....::
. ..................:............:+j:::.:..+j+:.::.:::+jj++::.:....:.:...::.:.......:.
. .................:.............:++::+:::+jj+.:::::.:::::.::......:..:.:...:..:..:...
. ................:.............::+:::::::+j+:.+:::.:++:.::......:..::.:...:.:.....:..
. ..............................::+:+j+::jj+:.::.::.::.::.::.....:..:.....:.::........
. :..............................:::.+jj+..::::+::+++++::.:.:.....::...:....:.:.....:.
. ...............................:::+jjj:::j:::::+::::::.:..:.....:.::....:....:......
. .:.............................::.++j+.++j:..:+::.++.:....................:.........
. ..............................:++:++j+:.:j..:j:.:j+::....................:.:........
. ...............................:::j:..+j66+++++++:.:.................:....:.........
. ......................:.........:++.:+jjjj:.:.:++.................................:.
. ..............................:::j::::jj6+..:.:+...................................:
. ...............................:::..:++j6::+:.:.....................................
. ............................:+jjjjjjjj+j+.+::...::..................................
. ............................::+++j6j666j66jj:.......................................
. .............................::::.+::+:jjj+:........................................
. ..............................:..:j:::+j+.::.............................:.......:..
. .............................::::+j:.+6jj...........................................
. ...........................::::::j::+jj:............................................
. ...........................:+::+jj++jjj.............................................
. ...........................:::::+.:++j::............................................
. ...........................::::+:::+j:..............................................
. ...........................:::::::+j+.:.............................................
. ..........................::::+:.:j:................................................
. ..........................+::+j:+j:.................................................
. ..........................+:.:::::..................................................
. .........................:+::+:::...................................................
. .........................:::.+.:....................................................
. .................::::...::+:.+:.....................................................
. ........................::.:::::....................................................
. ........................::.+::......................................................

Name: Anonymous 2010-12-17 1:39

Erika once told me that Xarn is a bad boyfriend

Name: Anonymous 2013-09-01 11:09



                / /<___/`ー'´::::::::::::!  \__>-、_ \
               ///:;ハ:::::::::::::::::::::::::::::::    /\_| \ \
              _r|./::/!:::ト、:::::::::::::::::            |   \ ':,
   ト.、         |_/:::/:::::|:::|::::::        :  /     \__,ハ ',
   |::::|`ー‐--、   _//‐‐-/::/__.   \     i /          `| ハ
   ∨ヽ、 ̄\:::Y´/:/    /::/  `' 、  \   /〉'             |  |
    \::`<´|:/´_]く__r‐-'-‐ァ─-、   \   //--  ─       ̄\_!
     /\_,>r'´   _」-─-'、_  \   '、.//              〈_,|
   _ノ´ ̄   ,>‐ '"´        \_/ ̄i___//              / イ
  く__/ ̄ ,>'´     ,  i      ヽ. \__.//|〉              / /
  / \,./   i    /|  ,ハ-‐-八    ',   //へ、          / /
  └-、/7     !-‐ァ' |/ァ'〒テァt\   | //ハ‐、/__   __,,.. -‐''"´i/
    └|  `ヽ| ァ'=‐     ゝ-‐'´ | \.|//  |‐'_r、  ̄  ,|_r‐'´
     `ヽ.  ,ハ ,.  ,     "/|/ //   ,ハ、  ` ̄ ̄
       )イ /|    _ _,.  / / .//   /   \
  ト、    /.レ' .ト 、,       / / >//-‐-'、   ,!  \
 /::::|  /  /  | /|`>/7 ̄`ーく7://::::::::::::::`Y .|   ',\
く:::::_|7´ _/!  |'_」/ァ//    /:://:::::::::::::::::::::∨    ! ハ
 >'´ヽ,イ::`7| ./::::/| //  /|:::://!::::::::::::::::::::::::|   | /  i
ノ`Y´\::/ |/:::::::/ ,// /ノ´`ヽ/ |::::::::::::/::::::::::〉 ./| ノ⌒7
  /   /  /::::ァ'´二`''く/(i/´   ∨r‐、_/::::::::;:イ//|く::::::く
 ,| /  r〈:::::/  -‐ノ`ー':〈_r-、   |/´ ̄`ヽこン'./ .| \_j、
/ レ'   r〉ー/   ン'〈/:::|__/ /、   \    /イ /   ,ハ 〈  \
 ,|    i7/   /::::::::::/ / /:::ヘ   \ /| |/ / ,| ノ    )

Name: Anonymous 2013-09-02 13:07

Name: Anonymous 2013-09-03 0:24

Lovely language.

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