Cin W/ cout having a glitch

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 1567 Views - Last Post: 19 January 2009 - 02:02 PM Rate Topic: -----

#1 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Cin W/ cout having a glitch

Posted 17 January 2009 - 11:49 AM

Ok this is really pissing me off to the point where i"m coming here. For some reason my program is glitching on me when I try to get it to pull what the user entered for name using cin, into a cout statement. Whenever I try it pulls the first letter into the cout then types the rest after the part of the script is done causing my doagain statement to glitch from receiving the other 2+ letters from the name. I've tried many methods of fixing this but its just being really frustrating.

cin >> name;
goto Identity;

...


	if (strcmp(awnser, "Identity")== 0){
					   Identity: 
					   system("CLS");
					   cout << "You are currently logged onto SIONET"  << endl;
					   Sleep(600);
					   cout << "Username: " << name << endl;
					   Sleep(600);
					   cout << "Password: *****" << endl << endl;
					   Sleep(600);
												
					   }


Is This A Good Question/Topic? 0
  • +

Replies To: Cin W/ cout having a glitch

#2 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 11:57 AM

I may be wrong, but I don't think C/C++ supports the GOTO statement. Even if it does, you are GOTOing the middle of a conditional statement, resulting in broken code and broken program execution.
Was This Post Helpful? 0
  • +
  • -

#3 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 11:59 AM

It is supported. and I just have it posted as it leaving in the middle but in my code it truely isn't.

EDIT: Posting Code

	if (strcmp(awnser, "7")== 0){
					   system("CLS");
					   cout << "Welcome to the SSI Tour Station" << endl;
					   cout << "Enter your name to procede:";
					   cin >> name;
					   goto Identity;						  
					   }

This post has been edited by Blade2021: 17 January 2009 - 12:01 PM

Was This Post Helpful? 0
  • +
  • -

#4 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 12:04 PM

How much more code is there because I can't find any other immediate mistakes in the code posted..
Was This Post Helpful? 0
  • +
  • -

#5 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 12:10 PM

lol now thats awesome to hear that. but there is alot more code. The rest of my code shouldn't be causing such a mistake though. I truely don't understand it. I've done each part of my script one by one and making sure to end and close all parts.

! I've never done this while inside a switch. Would it being inside a switch cause it?

EDIT: Arg, Nevermind, I reviewed it and the part where its calls the name from cin is not in the switch statement.

This post has been edited by Blade2021: 17 January 2009 - 12:13 PM

Was This Post Helpful? 0
  • +
  • -

#6 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 12:12 PM

It's possible that the Goto will influence flag-bits on a lower level, causing unexpected errors.
Was This Post Helpful? 0
  • +
  • -

#7 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 12:15 PM

Well it even did that when it wasn't in the goto statement. Then I just wrote in into the goto statement like I planned too hoping it would fix it.
Was This Post Helpful? 0
  • +
  • -

#8 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 856
  • View blog
  • Posts: 2,339
  • Joined: 20-August 07

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 01:27 PM

Try rewriting your code without using goto. This looks like a good example of how goto can make hard-to-follow "spaghetti" code with all kinds of subtle problems
Was This Post Helpful? 0
  • +
  • -

#9 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 01:47 PM

As I was saying earlier, your GOTO puts program execution inside a block of code. I'm betting since there is an end block character without a beginning block character, the compiler is confused what you want it to do.

If you must use GOTO statements, make absolutely sure they don't intersect blocks of code.
Was This Post Helpful? 0
  • +
  • -

#10 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 02:28 PM

Well I tried without using goto and it still has the same error and also I have this same kind of layout for my Administration Section of my program and it works fine.
Was This Post Helpful? 0
  • +
  • -

#11 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 02:37 PM

What's the error?

My guess is that if you're getting a read error your cin stream is bad you could always do a:

if(cin.bad())
{
	cerr << "Oh bother" << endl;
}


to check
Was This Post Helpful? 0
  • +
  • -

#12 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 02:42 PM

There is no error when it complies but it is "glitching". Its only using the first letter that the user inputs then it uses the rest after the section of the script is closed causing the doagain to fail.
Was This Post Helpful? 0
  • +
  • -

#13 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 02:53 PM

What data type are you inputting to?

And as has been said "Goto is bad." If you can rewrite your code to avoid its' use, do it.
Was This Post Helpful? 0
  • +
  • -

#14 Blade2021  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 31-October 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 02:59 PM

I have no idea what you mean by data type. I dont' think i'm that advanced yet and its not required that I have this feature but it would really help out. and i've rewritten it without the goto's and still same problem.
Was This Post Helpful? 0
  • +
  • -

#15 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: Cin W/ cout having a glitch

Posted 17 January 2009 - 03:03 PM

Data type as in:
int
char
bool
byte
float
double
...
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3