Home > Mobile >  how to make terminal ask for string then after string is received remove it
how to make terminal ask for string then after string is received remove it

Time:05-18

hi so I'm making a mini bank and I want to have the user put in the email and then once they put it in it clears and then moves to the password I'm having trouble doing that please help.

#include <iostream> 
#include <windows.h>
#include <String>
#include <thread>
#include <stdlib.h>

int main() {
    int money = 1000000;
    std::string password;
    std::string email;
    std::string Inpassword;
    std::string Inemail;
    std::cout << ("Welcome to the bank of jack!\n");
    Sleep(2000);
    std::cout << ("Enter your email:  ");
    std::cin >> email;
//the user enters the email and then once the user inputs the email the computer clears the text containing the email 
    Sleep(3000);
    std::cout << ("create your password: ");
    std::cin >> password;
//user inputs password and then once its pasted the computer clears it 
    Sleep(1000); 
    std::cout << ("Account created\n");
Sleep(1000);
//after that the entire terminal is cleared
    std::cout << ("Log in\n");
    Sleep(1000);
    std::cout << ("enter your email\n");
    std::cin >> Inemail;
    if (Inemail == email) {
        std::cout << ("user ") << email << (" located");
    }
    else {
        std::cout << ("incorrect email");
        exit(0);
    }
}

CodePudding user response:

Have you tried using the system function from cstdlib to execute the cls command to clear the console before Asking for Password.

Example Usage:

system("cls");

So Your Code is modified as below to clear the terminal after inputting the email and password.

#include <iostream> 
#include <windows.h>
#include <String>
#include <thread>
#include <cstdlib>

int main() {
    int money = 1000000;
    std::string password;
    std::string email;
    std::string Inpassword;
    std::string Inemail;
    std::cout << ("Welcome to the bank of jack!\n");
    Sleep(2000);
    std::cout << ("Enter your email:  ");
    std::cin >> email;
//the user enters the email and then once the user inputs the email the computer clears the text containing the email 
    Sleep(3000);
    system("cls");
    std::cout << ("create your password: ");
    std::cin >> password;
//user inputs password and then once its pasted the computer clears it 
    Sleep(1000); 
    system("cls");
    std::cout << ("Account created\n");
Sleep(1000);
//after that the entire terminal is cleared
    system("cls");
    std::cout << ("Log in\n");
    Sleep(1000);
    std::cout << ("enter your email\n");
    std::cin >> Inemail;
    if (Inemail == email) {
        std::cout << ("user ") << email << (" located");
    }
    else {
        std::cout << ("incorrect email");
        exit(0);
    }

If you are on a Linux/Mac Environment be sure to replace the cls command with clear. Hope this Helps

CodePudding user response:

got it fixed used system("cls"); thanks Adityan.P

  •  Tags:  
  • c
  • Related