Click here to Skip to main content
15,884,388 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: User Input revisted 2 Pin
David Crow12-Jul-06 5:17
David Crow12-Jul-06 5:17 
AnswerRe: User Input revisted 2 [modified] Pin
Harold_Wishes12-Jul-06 5:39
Harold_Wishes12-Jul-06 5:39 
GeneralRe: User Input revisted 2 Pin
David Crow12-Jul-06 5:53
David Crow12-Jul-06 5:53 
GeneralRe: User Input revisted 2 [modified] Pin
Harold_Wishes12-Jul-06 6:12
Harold_Wishes12-Jul-06 6:12 
GeneralRe: User Input revisted 2 Pin
David Crow12-Jul-06 6:33
David Crow12-Jul-06 6:33 
GeneralRe: User Input revisted 2 Pin
Zac Howland12-Jul-06 10:12
Zac Howland12-Jul-06 10:12 
GeneralRe: User Input revisted 2 [modified] Pin
earl12-Jul-06 8:52
earl12-Jul-06 8:52 
GeneralRe: User Input revisted 2 [modified] Pin
Harold_Wishes12-Jul-06 10:04
Harold_Wishes12-Jul-06 10:04 
I think this code below compiles. I only reformatted. I shortened the logic in the program as suggested and it works. The only problem I'm having is duplicate output (something I encountered last week). Below the user is prompted to enter data twice in sequence. The first time the user is prompted to make a selection from a menu screen (no big deal).

But, after the user hits the ENTER key, the user will see duplicates of the second prompt. It is as if the user hit the enter key twice.

How do I prevent this from happening? Better question . . . Why is it happening?

I know the compiler is taking me thru the while loop an extra time which is printing the duplicate prompt (confirmed by the debugger). Frown | :(

#include <cstring>
#include <string>
#include <iostream>


using namespace std;



int main()
{
    int data2;
    char buff[1024];
    unsigned int value;
    int charsRead; 

    char selection;
    cout << "A) Complete  B) Partial  C) UNKNOWN" << endl;
    cin >> selection;



    bool validEntry = false;
	while (!validEntry)
	{ 
		cout << "Please enter the number of subunits: ";
		cin.getline(buff, 1023, '\n');

		if (sscanf(buff, "%u%n",&value,&charsRead)==1 && value >=1 && value <= 12)
		   validEntry = true;
	}

	data2 = value;

  return 0;

}


-- modified at 21:56 Wednesday 12th July, 2006
Questionpthread Pin
mehmetned12-Jul-06 4:55
mehmetned12-Jul-06 4:55 
AnswerRe: pthread Pin
toxcct12-Jul-06 4:58
toxcct12-Jul-06 4:58 
GeneralRe: pthread Pin
led mike12-Jul-06 5:02
led mike12-Jul-06 5:02 
AnswerRe: pthread Pin
David Crow12-Jul-06 4:58
David Crow12-Jul-06 4:58 
AnswerRe: pthread Pin
led mike12-Jul-06 5:05
led mike12-Jul-06 5:05 
AnswerRe: pthread Pin
Jun Du12-Jul-06 5:08
Jun Du12-Jul-06 5:08 
Questionoverzealous protection rules Pin
Dave Schumann12-Jul-06 4:53
Dave Schumann12-Jul-06 4:53 
AnswerRe: overzealous protection rules Pin
toxcct12-Jul-06 4:56
toxcct12-Jul-06 4:56 
GeneralRe: overzealous protection rules Pin
Dave Schumann12-Jul-06 5:02
Dave Schumann12-Jul-06 5:02 
AnswerRe: overzealous protection rules Pin
Dave Kerr12-Jul-06 4:59
Dave Kerr12-Jul-06 4:59 
GeneralRe: overzealous protection rules Pin
Christian Graus12-Jul-06 5:00
protectorChristian Graus12-Jul-06 5:00 
GeneralRe: overzealous protection rules Pin
toxcct12-Jul-06 5:05
toxcct12-Jul-06 5:05 
GeneralRe: overzealous protection rules Pin
Dave Kerr12-Jul-06 5:08
Dave Kerr12-Jul-06 5:08 
GeneralRe: overzealous protection rules Pin
Dave Schumann12-Jul-06 5:29
Dave Schumann12-Jul-06 5:29 
GeneralRe: overzealous protection rules Pin
Dave Schumann12-Jul-06 5:04
Dave Schumann12-Jul-06 5:04 
AnswerRe: overzealous protection rules Pin
Maximilien12-Jul-06 4:59
Maximilien12-Jul-06 4:59 
AnswerRe: overzealous protection rules Pin
David Crow12-Jul-06 5:10
David Crow12-Jul-06 5:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.