LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 525 users online 211554 members 1506 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
breakupnow
I haven't filled out my profile...
Days Active: 9
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
4 online / 42 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Issue with basic C++ Program
Replies: 6Last Post May 16, 2008 11:15am by i who have nothing
Welcome to LiveWire!
We're Stronger Together.
Join the Community
Single page for this topic Email Print Favorite
( Jx2 Anarchy )


Quality Control Engineer
Reply
im wiritng a program for my C++ class, here is the source

http://www.miraclesalad.com/webtools/clip.php?clip=1491

its not completed, alot of stuff is left out, but, im trying to figure out why im getting the issue i am. (for the questions asked to continue, Y and N are answers atm)

basically when i run the program and go into the fortune part of it (b) and i ask it a question, it outputs an answer, but instead of asking to continue, it goes over the answer, assumes you want to continue, and give an answer for a question you dont have in. then askes if you want to continue.

obviusly this isnt right, and, when asked with anything that is only one word (no spaces) it seems to work correctly, anyone have an idea of what i have wrong here?

Post edited at 1:55 pm on May 15, 2008 by Jx2 Anarchy


1:54 pm on May 15, 2008 | Joined: Aug. 2007 | Days Active: 75
Join to learn more about Jx2 Anarchy United States | Posts: 175 | Points: 930
GdFtherOFCOWS


Swami

Patron
Reply
Sounds like you have having trouble with the char input.

Try this.

char question[75];

"Put that underint programContinue = 1;" and "char menuChoice;"


Delete the "string question" in function();

-------
Transvestites are men who like to eat, drink and be Mary.
Let's do the Time Warp Again!
Hymen Destroyer


2:08 pm on May 15, 2008 | Joined: Mar. 2004 | Days Active: 1,295
Join to learn more about GdFtherOFCOWS Arkansas, United States | Male | Posts: 14,032 | Points: 27,206
Just Waiting Here


Dairy Product Addict

Patron
Support Leader
Reply
I'm not too familiar with cin, so I looked around.

http://www.macs.hw.ac.uk/~pjbk/pathways/cpp1/node185.html


When the input stream cin is used space characters, newline etc. are used as separators and terminators. Thus when inputting numeric data cin skips over any leading spaces and terminates reading a value when it finds a white-space character (space, tab, newline etc. ). This same system is used for the input of strings, hence a string to be input cannot start with leading spaces, also if it has a space character in the middle then input will be terminated on that space character.

Looks like you may have to make a loop of some kind to pick it all up?  I dunno... I also thought of what GdFtherOFCOWS said, and hopefully that will work.  Otherwise, you may need a loop to pick up all the words in the string, and only consider it as one...?

Lol, sorry I'm useless, it's been 4 years now since I've touched C++ and I never actually was taught the cin function...  I'm interested in knowing how you got around the problem though, if you do figure it out :).  But I think the problem all comes to the string and how cin works.


2:26 pm on May 15, 2008 | Joined: Dec. 2007 | Days Active: 425
Join to learn more about Just Waiting Here United States | Posts: 10,819 | Points: 16,647
( Jx2 Anarchy )


Quality Control Engineer
Reply
the thing that gets me is i know it ran BEFORE i put it into this code  (it was its own beforehand, i just copied it in)  after i put it in though, it started this, and i have no clue in how to fix it.

i tired what GdFtherOFCOWS said, but i still get the same error.


2:43 pm on May 15, 2008 | Joined: Aug. 2007 | Days Active: 75
Join to learn more about Jx2 Anarchy United States | Posts: 175 | Points: 930
( Jx2 Anarchy )


Quality Control Engineer
Reply
and incase it helps, the origional source of the fortuneteller

http://jx2anarchy.com/random/source.txt


2:46 pm on May 15, 2008 | Joined: Aug. 2007 | Days Active: 75
Join to learn more about Jx2 Anarchy United States | Posts: 175 | Points: 930
JudeLaurence


[neVer forgeT]

Patron
Reply
In school I never used the string type.

After using cin, there is a newline character trailed behind.  Use a "dummy" variable to grab the newline or simply have two cin>> quit1; statements.  That'll fix it. :)

-------
Please change your signature.


7:28 pm on May 15, 2008 | Joined: April 2004 | Days Active: 1,388
Join to learn more about JudeLaurence Virginia, United States | Lesbian Male | Posts: 16,077 | Points: 33,176
i who have nothing


Executive

Patron
Reply
add

cin.clear();

above

cout<<"Would you like to ask the fortune teller another question?"<<endl; //askes user if they would like to quit

the input stream is retaining characters and messing everything up.


11:15 am on May 16, 2008 | Joined: Mar. 2008 | Days Active: 119
Join to learn more about i who have nothing Ontario, Canada | Straight Male | Posts: 2,559 | Points: 3,473
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic