while loop "breaking" because of cin.get?

I have a cin.get() in a while loop, but when it should pause the loop and wait for user input it just makes the loop go boom and it begins to run uncontrolled like if there was no pause at all. Whats wrong? The cin.get is in the beginning.

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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "conio.h"
#include "time.h"
#include <iomanip>

using namespace std;
char encrypt(){
     char word_enc[200];
     cout<<"\n\n\n\t\t\t\t*Encryption*\n\n\t\t"<<
     "Enter a word or a string or words which you want to encrypt: ";  cin.get(word_enc, sizeof(word_enc)); cin.ignore(1000, '\n'); //this is the cin.get that screws up the loop
     
     
     
     }
char decrypt(){}
int main();


int menu(){
     int running=1;
     char menyval;
     while(running!=0){
     cout<<"\n\n\n\t\t\t\t*Menu*\n\n\t\t"<<
     "1. Encrypt.\n\n\t\t"<<
     "2. Decrypt.\n\n\t\t"<<
     "3. Logout." ; cin>>menyval;
     switch(menyval){
                        case '1': encrypt(); running=0; break;
                        case '2': decrypt(); running=0; break;
                        case '3': break; return 0;
                        
                        }
     
     }}
char registration(){
     string password;
               cout<<"Write a password: "; cin>>password;
               ofstream out("registreting.txt");
               if(!out) return 0;
               out<<password;
               out.close();
               cout<<"Password set.\n\n";
               main();
              }
char check_reg(){
     system("CLS");
     string password, wrote_password;
     int left=3, running=1;
     while(running>0){

     cout<<"Password: "; cin>>wrote_password;
     ifstream in("registreting.txt");
     if(!in) return 0;
     in>>password;
                     if(password==wrote_password){
                                                  cout<<"\n\n\t\t*Passwords match*";menu();}
                     else if(password!=wrote_password){
                                                  left=left-1;
                                                  if(left==2){
                                                  cout<<"\n\n\t\t*Passwords does not match. You have "<<left<<" tries left*";}
                                                  else if(left==1){
                                                       cout<<"\n\n\t\t*Passwords does not match. You have "<<left<<" try left*";}}
                     if(left==0){
                                 cout<<"\n\n\t\tYou have failed me for the last time commander.\n\n\t\tYou will have to wait in agony for 30 seconds before\n\n\t\tattemting to enter a password again.";
                                     int msek=30000;
                                     clock_t start=clock();
                                     while (clock()-start<msek);
                                     check_reg();}}}


int main()
{
    int running=1;
    char vault_choice;   
    
    while(running>0){
    cout<<"\n\n\n\t\t\t\t*Vault*\n\n\t\t"<<
    "1. Log in.\n\t\t"<<
    "2. Register.\n\t\t"<<
    "3. Exit."; cin>>vault_choice;
    
    switch(vault_choice){
                         case '1': check_reg(); running=0; break;
                         case '2': registration(); running=0; break;
                         case '3': return 0;
                         default: cout<<"That is not a word that I know of";}
                         }
    
    system("PAUSE");
    return 0;


}
your functions "decrypt" and "encrypt" must return value.
Topic archived. No new replies allowed.