help using cin.get()

I have posted parts of this program before but am having trouble using the cin.get(); to replace system("PAUSE";. When I use it in this function it doesn't pause the system before it clears the screen. I have tried it in Dev C++ and in Code::Blocks. Also have tried different versions of the system("CLS") but I don't get the desired results. Any input would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<limits>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<ctime>
#include<iomanip>
#include <algorithm>
using namespace std;

void seedADeckOfCards(vector<int>&);
void dealFiveCardHand(vector<int>&, int [], char [], int [], char [],
                      const double, const double);
void exchangeCards(int[], vector<int>&, int&, char [], const int [],
                   const char[], const double, const double);
bool wantToSwapcards();
void outputDeck(const vector<int>&);
void showHand(const int[], const char[]);
void showWinningsMenu();
void getBet(const double, double&);
void displayTotalAndBet(const double, const double);
void displayOriginalHand(const int [], const char []);
void displayOrigAndNewHand(const int [], const char [],
                           const int [], const char []);

const int HAND = 5;
string hold;

int main()
{
    char suit[HAND];
    int num = time(0);
    srand(num);
    vector<int> cardDeck;
    int cardHand[HAND], orignalHand[HAND];
    char originalSuit[HAND];
    double total = 1000;
    double bet = 0;
    cout << setprecision(2) << fixed << showpoint;
    char playAgain;

    do
    {
     system("CLS");
     showWinningsMenu();
     getBet(total, bet);
     system("CLS");
     showWinningsMenu();
     displayTotalAndBet(total, bet);

     seedADeckOfCards(cardDeck);
     std::random_shuffle(cardDeck.begin(), cardDeck.end());
     dealFiveCardHand(cardDeck, cardHand, suit, orignalHand, originalSuit,
                     total, bet);
     system("CLS");
     showWinningsMenu();
     displayTotalAndBet(total, bet);
     displayOrigAndNewHand(orignalHand, originalSuit, cardHand, suit);

     do
     {
      cout << "\nDo you want to play another hand? (Y or N)";
      cin >> playAgain;
      if(!(playAgain == 'Y' || playAgain == 'y' ||
           playAgain == 'N' || playAgain == 'n'))
           cout << "Invalid Entry! Enter Y or N Only";
     }while(!(playAgain == 'Y' || playAgain == 'y' ||
           playAgain == 'N' || playAgain == 'n'));
    }while(playAgain == 'Y' || playAgain == 'y');

    system ("PAUSE");
    return 0;
}

void seedADeckOfCards(vector<int> &deckOfCards)
{
     for(int i = 0; i < 52; i++)
     deckOfCards.push_back(i+1);
}

void dealFiveCardHand(vector<int> &deckOfCards,
                      int cardHand[],
                      char suit[],
                      int originalHand[],
                      char originalSuit[],
                      const double total,
                      const double bet)
{
     int card;
     int dealFromBack = 51;
     for(int i = 0; i < HAND; i++)
     {
      cardHand[i] = deckOfCards[dealFromBack] % 13 + 1;
      cout << "CARD " << (i+1) << "  = ";
      cout << setw(3) << cardHand[i] << " ";
      suit[i] = deckOfCards[dealFromBack]%4+3;
      cout << suit[i] << endl;
      deckOfCards.pop_back();
      --dealFromBack;
      originalHand[i] = cardHand[i];
      originalSuit[i] = suit[i];
     }

     exchangeCards(cardHand, deckOfCards, dealFromBack, suit,
                   originalHand, originalSuit, total, bet);

     cout << "Your Original Hand: \n";
     displayOriginalHand(originalHand, originalSuit);

     cout << "Your New Hand: \n";
     showHand(cardHand, suit);
     cout << endl;
}
the getBet() function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void getBet(const double total, double& bet)
{
     bool inputGood = false;

     do
     {
     cout << endl;
     cout << "Your Total = $" << total << endl;
     cout << "Bet        = $";
     inputGood = std::cin >> bet;

     if(!inputGood)
     {
      std::cout << "\nERROR! Invalid Entry." << endl;
      std::cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
      system("PAUSE");
      system("CLS");
      showWinningsMenu();
      while( cin.get() != '\n' )cin.clear();
     }

     else if(bet < 0)
     {
      cout << "\nNo Negative Numbers. \n";
      system("PAUSE");
      system("CLS");
      showWinningsMenu();
      while( cin.get() != '\n' )cin.clear();
     }

     else if(bet > total)
     {
     cout << "\nYou dont have enough money to make that bet.\n";
     system("PAUSE");
     system("CLS");
     showWinningsMenu();
     while( cin.get() != '\n' )cin.clear();
     }
     }while(!inputGood || bet > total || bet < 0);
     std::cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
}
Any problem you are having with cin.get() I will bet is coming from an uncleared input buffer. So here is a way to fix that:

1
2
3
4
5
6
7
#include <limits>
#include <iostream>

...

std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cin.get(); //Now call cin.get() 
the std::cin.get(); did not fix my problem. The error message output to the screen just flashes for a 1/4 second. before the system("CLS") clears the screen
Try system("pause"); //lowercase

Also take a look at this thread it might give you some ideas:
http://www.cplusplus.com/forum/beginner/1988/
system ("PAUSE") is the same as system("pause") they both work the same in all three of my IDE's
Topic archived. No new replies allowed.