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

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-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.

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