How to display asterisks (***) [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to create an ATM application using c++ and I want to display asterisks (****) when I input the pin code. I haven't tried anything because I have no idea on how to do it.
Could someone help me?

A very small program which should help you get started for Windows would go like this:
int main(void)
{
char character = 0;
while (true)
{
character = _getch();
if (character == 13) //Enter
break;
else
{
putc('*');
//Do whatever
}
}
}
Please note that this code is off the top of my head and still requires the correct includes, but should point you in the right direction.
Please refer to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getch-getwch?view=msvc-160 for the documentation of _getch and http://www.asciitable.com/ for a list of control codes you might be getting.

Related

How to use if commands with sentances [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I am currently learning c++ and creating an assistant for myself. I need to make sure the if command checks for a sentence, not a word in a string how do I do that.
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
const string YES = "yes";
const string NO = "no";
//ignore this
int main () {
std::string Question;
std::string check;
std::cout << ("Hi sir how may i assist you?\n");
//user asks the question and then a if command checks the question from a list of questions and if the line is the same as in the database it gives a output
getline (cin, Question);
if (Question == "whats the weather?") {
std::cout << ("Well it is...\n");
//then it pulls data from the web and puts it in here
}
}
Output
Hi sir how may I assist you?
whats the weather
(nothing) else happens
In this:
if (Question == whats the weather?)
Add quotes around the sentence. You want to write
if (Question == "whats the weather?")
Also, since you're using namespace std, you don't need std:: before anything.
You can check for specific sentences with a syntax like:
if (Question == "whats the weather?")
However, to make your assistant more quickly usable you may instead want to lead them through some menus in the chat window, with them selecting from topics and functions. Just a suggestion to make developing your assistant easier.

How to get available space on a network drive in c++? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I tried using std::filesystem::space(dir) but with no luck -> it cannot determine available disk space, sets it to uintmax.
auto info = std::filesystem::space("K:\\Dir");
if(info.available == static_cast<uintmax_t>(-1))
{
std::cout << "Error occurred!\n";
}
K:\Dir does indeed exist. And this snippet prints Error occurred for my drive mounted on K:.
If you want to get the free space you need to try
const std::filesystem::space_info spaceInfo = std::filesystem::space(dir);
cout << static_cast<std::intmax_t>(spaceInfo.free) << endl;
Here dir = "/path/to/dir/";
Refer cppreference

I have a question about my battle system hp code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
i've been coding a text based RPG pokemon battle and im trying to make a damage count of the wild pokemon. but i'm slightly stuck. i have the link to the running program so you can see what i mean.
https://repl.it/live/Ig6yy9UVHyxScw
ive tried using if the total hp of the wild pokemon is less than 90 but it still shows the first attacks damage. (damage = 20). i have the code i'm stuck on here.
if (pokemonSelect == 1 == move == 1) {//for charmander
wPhPtotal = wPhP;
wPhPtotal = wPhP - wPdamage;
}
cout<<"wild pokemon hp lost:" << red<<" "<<wPdamage<<" "<<def<< "hp:"<<green<<wPhPtotal<<endl;
NOTE: only use charmander and ember as i havent programmed the other moves yet.
is there A way to count it all up?
There's not enough information to really answer your question, but here's some stuff that might point you in the right direction.
Firstly, you can't chain ==, as you may be able to in other languages.
if (pokemonSelect == 1 == move == 1)
Should be
if (pokemonSelect == 1 && move == 1)
As a side note, you can write it the way you have it in this particular instance. However, that's mostly due to luck, and it won't work for any values
other than 1. This is because x == y returns 1 if true and 0 if false. So, for any value other than 1 in that conditional, it'll break.
Second,
wPhPtotal = wPhP;
wPhPtotal = wPhP - wPdamage;
Is redundant, since the second line will overwrite the first.

Is it possible to create "quick time events" in C++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have some knowledge about C++, but I stumbled upon an problem. I want the user to enter some text, but when it takes longer than X seconds, the program will go on. I guess, it is not possible, but maybe you know something about it.
It will be in the command line, without GUI.
I am not certain how the programm will look like, but it will be something like a CMD-RPG. I wanted to use Quick Time Events to make it a little bit more exciting.
I cant comment so I will just leave this here
Input with a timeout in C++
Since I cannot comment, I will simply leave this as an answer.
One possible way to solve this problem is to have 2 threads:
Input capture thread: since receiving input is a thread-blocking action, you should have a thread that simply polls for user input, placing that input into a thread-safe buffer
Quick-time function on main thread: a function that will be responsible for executing the quick-time event. Something like the following could be done (pseudo code):
clear input buffer //the buffer provided by the input capture thread
bool success = false;
while(current time < ending time)
{
if(input buffer isn't empty)
{
get contents of input buffer and send contents to cout
if (user has finished input correctly)
{
success = true;
break;
}
clear buffer
}
}
return success;
For this to work, you would need to turn off echo on the command prompt (see this page for more info)
Although Diogo's reference is excellent (and informative), I believe this answer is more applicable than since the OP has indicated that this program will be ran on Windows.

Ncurses: movement [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a problem with programming movement using C++ and Ncurses.
I'm programming a pacman and the main problem is, that I just want last pressed key in time period.
When I use usleep, it saves every key pressed during sleeping and then it's working with that in the order.
Thanks for ideas.
What did you try?
Something like this should work, if I understood correctly what you try to achieve:
int t = your_delay;
while (t --> 0)
{
sleep(1);
c = getch();
}
If you really need to time it down to the microsecond, this might not be the best approach, but if you can have some tolerance, this should be enough.
Are you in no-delay mode? If so, this might work:
usleep(your_delay);
last_key = ERR;
while ( (key=getch()) != ERR ) {
last_key = key;
}
// "last_key" now holds most recent key, if there was one, else ERR