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.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "conio.h"
#include "time.h"
#include <iomanip>
usingnamespace 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();}
elseif(password!=wrote_password){
left=left-1;
if(left==2){
cout<<"\n\n\t\t*Passwords does not match. You have "<<left<<" tries left*";}
elseif(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;
}