user inputprompt does not wait for user input
24 Replies - 2599 Views - Last Post: 04 November 2010 - 04:58 PM
#1
user input
Posted 03 November 2010 - 05:55 PM
I just have a quick question. Why would the user prompt not wait for the input? I am using visual studio 2008. It is a quick program as I am learning. I wondered if there were preferences set so that it automatically comes up and says "hit any key to continue". The problem is that the message is before the prompt and so hit a key and you are out of the program. Any thoughts on the subject would be appreciated.
thank you,
lobabyg
Replies To: user input
#2
Re: user input
Posted 03 November 2010 - 05:58 PM
cin.getline();
Should do the trick.
This post has been edited by SarumanTheWhite: 03 November 2010 - 05:59 PM
#3
Re: user input
Posted 03 November 2010 - 06:21 PM
#4
Re: user input
Posted 03 November 2010 - 07:02 PM
SarumanTheWhite, on 03 November 2010 - 04:58 PM, said:
cin.getline();
Should do the trick.
Hi,
Thank you for the quick reply. However, it is not for the window vanishing too quickly but rather for "Hit any key to continue" getting in front of the user prompt. The program prompts for the user to input a number there is no way to put in the input. The message pops up before the cursor. So if the user hits any key then out of the program they go--with no input. Is this set automatically somehow?
Thanks
lobabyg
#5
Re: user input
Posted 03 November 2010 - 07:16 PM
#6
Re: user input
Posted 03 November 2010 - 08:38 PM
Please post the code that has this behaviour between code tags, like this
#7
Re: user input
Posted 03 November 2010 - 10:26 PM
janotte, on 03 November 2010 - 07:38 PM, said:
Please post the code that has this behaviour between code tags, like this
Hi,
I'm sorry but I was not exactly sure what you meant by between the tags. On yours or what? Just remember, I do not know anything or very little about coding.
/cout << "\n\nEnter a number = "; /
I want to say that every other part of the code is fine. This only happens on this line. Before that I have user input for about three or four lines and it works perfect. I like to figure things out on my own but since I am using the same code for the other inputs and they work I just could not understand what it could be. Oh, and thank you for your patience and time.
lobabyg
#8
Re: user input
Posted 04 November 2010 - 12:43 AM
lobabyg, on 04 November 2010 - 02:26 PM, said:
This is not coding.
This is just how to show us your code.
Look at this
Do you see the first tag? The text in the first square brackets? Type that including the square brackets.
Then copy and paste your code
Then type the closing tag The text in the second square brackets? Type that including the square brackets.
Click the "Preview Post" button.
Does your code show up in the preview nicely laid out with line numbers running down the left hand side?
If it does you have got it right. Click the "Add Reply" button.
If not, keep trying until you get it right.
lobabyg, on 04 November 2010 - 02:26 PM, said:
And I want to say that, as much as I would like to believe you on that point, the evidence is against you.
Your program is not behaving as you would like it to. There is a 99.99% probability is that the reason for that misbehaviour is in your code.
Unless you show us all your code so we can look at the problem in context and give you suggestions as to how you might fix this problem we aren't able to help you further.
The decision is yours.
#9
Re: user input
Posted 04 November 2010 - 07:10 AM
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Global Declarations of Variables
double iovertime_hours=0, iovertime_pay=0, iovertime_extra;
int ihours, iwage ;
string cname ;
int main()
{
//Enter Employee Information
cout << "\n\nEnter the employee name = ";
cin >> cname ;
cout << "Enter the hours worked = ";
cin >> ihours;
cout << "Enter his or her hourly wage = ";
cin >> iwage;
// Determine if hours are greater than 40
if (ihours > 40)
{
//Do Calculations
iovertime_hours=ihours-40;
iovertime_extra=iovertime_hours*iwage+iovertime_hours*iwage*.5;
iovertime_pay = iovertime_extra*iovertime_hours>40;
// Display Employee Details
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
}
else // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
// End of the primary if statement
//End of Int Main
}
int cnum; //Part 2 enter a set of numbers; use a while loop
cnum = int (""); //use one variable to count the number of inputs
{ //Use the switch statement to count inputs under 100
cout << "\n\nEnter a number = ";
cin >> cnum ;
I did not start the while statement because I could not get the user input correct. Like I said everything works fine it just won't let me put in the input for the "Enter a number"
Thank you again for your time,
lobabyg
#10
Re: user input
Posted 04 November 2010 - 07:31 AM
#11
Re: user input
Posted 04 November 2010 - 07:56 AM
That is my point. It will not let me put a number in user input. Is there a setting on visual studio 2008 that makes the "press any key to continue" come up? That is what I am having a problem with. The code runs great until the "enter a number" and then it says"Press any key to continue." If you press a key then out of the program you go. No number gets entered.
Thank you,
lobabyg
#12
Re: user input
Posted 04 November 2010 - 08:23 AM
I mean, if you take your code, dump into a new project, and then compile and run that code do you still get the same problem?
#13
Re: user input
Posted 04 November 2010 - 09:25 AM
Thanks again for trying to help me. I did as you suggested but it still happens. I wonder if I am setting up the projects incorrectly or something? But then why would it be ok up until that point?
I also wonder why I get that "Press any key to continue" and you do not.
Thank you,
lobabyg
#14
Re: user input
Posted 04 November 2010 - 09:41 AM
EDIT: Also, right before you ask for a number, please copy paste this code:
if(!cin) std::cout << "Failbits set on cin.";
If the request for input is being skipped over, then it means the stream had a failbit set. Failbits get set because of previously failed I/O operations. That's why I asked for your previous input. I want to ensure that you aren't typing in something that would cause failure.
EDIT 2: In particular, your wage is an integral value. If you type in a number like 8.50 for the wage, which is not an integer, you will have a problem...
This post has been edited by Oler1s: 04 November 2010 - 09:44 AM
#15
Re: user input
Posted 04 November 2010 - 09:50 AM
Oler1s, on 04 November 2010 - 08:41 AM, said:
EDIT: Also, right before you ask for a number, please copy paste this code:
if(!cin) std::cout << "Failbits set on cin.";
If the request for input is being skipped over, then it means the stream had a failbit set. Failbits get set because of previously failed I/O operations. That's why I asked for your previous input. I want to ensure that you aren't typing in something that would cause failure.
EDIT 2: In particular, your wage is an integral value. If you type in a number like 8.50 for the wage, which is not an integer, you will have a problem...
|
|

New Topic/Question
Reply



MultiQuote





|