C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 26th, 2005, 02:33 PM
Ad1234 Ad1234 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 6 Ad1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 4 sec
Reputation Power: 0
cin.get will not work

Please tell me what I am doing wrong.

I have written this code

Code:
#include "Source.h"
 
 void initative()
 {
 
 int I;
 int y = 1;
 int x = 1;
 char YesNo;
 char Fall;
 char name[25];
 
 system("cls");
 
 cout << "INITATIVE TEST\n\n\n" 
 	 << "Some stuff about initative tests.\n"
 	 << "Please enter your characters name......" << endl;
 
 cin.get( name, 25);
 
 cout << "So " << name << " needs an initative test.\n"
 	 << "Is this a test to see if " << name << " will fall off an edge? (Y/N). " << endl;




but when the programe gets to the cin.get bit of the program it just ignores it like it isnt there and just gives me 25 white space characters.
What am I missing to get a user to input the info needed?
Thanks in advance Ad.

Reply With Quote
  #2  
Old April 26th, 2005, 05:20 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
well first of all, your initialize() function doesn't have a closing brace.

I don't know what is in Source.h, but the following program works fine in Dev-C++ 4.9.9.2 on Windows:
Code:
//#include "Source.h"
#include <iostream>
using namespace std;
 
 //void initative()
 int main()
 {
 
 int I;
 int y = 1;
 int x = 1;
 char YesNo;
 char Fall;
 char name[25];
 
 system("cls");
 
 cout << "INITATIVE TEST\n\n\n" 
	  << "Some stuff about initative tests.\n"
	  << "Please enter your characters name......" << endl;
 
 cin.get( name, 25);
 
 cout << "So " << name << " needs an initative test.\n"
	  << "Is this a test to see if " << name << " will fall off an edge? (Y/N). " << endl;
	  
	  return 0;
}

Reply With Quote
  #3  
Old April 27th, 2005, 02:22 AM
Ad1234 Ad1234 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 6 Ad1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 4 sec
Reputation Power: 0
Thanks for the help. The code is only the first part of the program that is called after main hence the missing brace and the name of the function.

After a bit more investigation what is happening is that if I rename this function to main and compile it without the rest of the program then it will prompt for the name successfully. However when compiled with the rest of the program it just skips over the get.cin command and inserts 25 white spaces.

In Source.h I have the following.

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>

as well as all my function declerations

void main();
void leadership();
void initative();
void fallen();

I am compiling it with MS Visual C++ Ver 6.

Any idea why it would be doing this?

Again thanks for the help.

Reply With Quote
  #4  
Old April 27th, 2005, 04:49 AM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
Quote:
Originally Posted by Ad1234
Thanks for the help. The code is only the first part of the program that is called after main hence the missing brace and the name of the function.

After a bit more investigation what is happening is that if I rename this function to main and compile it without the rest of the program then it will prompt for the name successfully. However when compiled with the rest of the program it just skips over the get.cin command and inserts 25 white spaces.

In Source.h I have the following.

#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <ctype.h>

as well as all my function declerations

void main();
void leadership();
void initative();
void fallen();

I am compiling it with MS Visual C++ Ver 6.

Any idea why it would be doing this?

Again thanks for the help.

try placing the following line of just before the cin.get()
Code:
fseek(stdin,0L,SEEK_END)

it's possible you have a newline or something in the buffer that needs to be flushed out...
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #5  
Old April 28th, 2005, 02:09 AM
Ad1234 Ad1234 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 6 Ad1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 4 sec
Reputation Power: 0
Thanks for the help but it is still skipping the cin.get command.

Reply With Quote
  #6  
Old April 28th, 2005, 07:52 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
I see you've edited your code in your origonal post.... the way it stands right now, does it not work? Because if it doesn't, you're compiler must be bugged or something, beause that's a darned simple, straight-forward program, I can't think of anything that would cause it to not work....

try compiling a program with nothing but a cin.get() and see if it works then, then you can see if it's a general cin.get() problem or just one specific to your code....

Reply With Quote
  #7  
Old April 30th, 2005, 06:07 AM
Ad1234 Ad1234 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 6 Ad1234 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 4 sec
Reputation Power: 0
I have tried compiling the program with just using the cin.get command and I have also inserted it into the main() function in this program and it works fine. When it stops working is when I call another function.

I am calling the other functions using a switch statement.

Any more ideas or could it just be my compiler ?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > cin.get will not work


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT