Thread: Hello can anyone convert this to <conio.h>/printf and scanf style

  1. #1
    Registered User
    Join Date
    Feb 2021
    Posts
    5

    Hello can anyone convert this to <conio.h>/printf and scanf style

    Can someone convert this to printf and scanf type? Im having trouble doing it.


    Code:
    #include <iostream>
    #include <string>
    
    
    
    
    int main()
    {
        //keep track of while loop
        bool correct = true;
        //Password user must enter to unlock
        int password = 123;
        //password user is entering
        int enteredPassword;
        //number of times user can enter password
        int numTries = 0;
        //continue asking until correct or 3 limit reached. 
        while(correct == true)
        {
            std::cout << "Password Checker" << std::endl;
            std::cout << "Please enter your password." << std::endl;
            std::cin >> enteredPassword;
            if(enteredPassword == password)
            {
                std::cout << "Correct password!" << std::endl;
                correct = false;
            }
            else
            {
                std::cout << "Wrong password!" << std::endl;
                numTries++;
                std::cout << "Attempted ";
                std::cout << numTries;
                std::cout << " out of 3." << std::endl;
                if(numTries == 3)
                {
                    std::cout << "Too many password attempted!" << std::endl;
                    
                    correct = false;
                }
            }
            
        }
    
    
    
    
    
    
    return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,036
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    Why don't you read the rest of the thread where you lifted the code from?
    How to give three attempt's to entered password
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf style output for C++
    By Mozza314 in forum C++ Programming
    Replies: 2
    Last Post: 11-09-2011, 12:31 AM
  2. Replies: 7
    Last Post: 08-07-2011, 04:54 PM
  3. Need help. printf() and scanf().
    By HBK in forum C Programming
    Replies: 19
    Last Post: 07-17-2011, 04:04 PM
  4. passing on printf()-style params?
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 07-16-2003, 05:13 PM
  5. something about printf (or maybe scanf)
    By netboy in forum C Programming
    Replies: 4
    Last Post: 06-11-2002, 10:26 PM

Tags for this Thread