program problem

problem with loop

Page 1 of 1

12 Replies - 1598 Views - Last Post: 11 March 2002 - 03:53 PM Rate Topic: -----

#1 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

program problem

Posted 03 February 2002 - 11:10 AM

I have a problem with my c++ program. the program works alright, but it's the problem with the default. it comes up "would you like to play the game. enter y or n and press enter." if you enter i, or another invalid entry, it comes up saying "follow directions try again, and press return." it's supposed to stop there to wait for re-entry of data, but it goes on to say "would you like to play the game? enter y or n, and press return". How do I get it to just say "follow directions..." and to leave out "would you like to play..."? i'm just going to copy and paste my program because i don't know any better way. someone help please!
//lettergame.ccp
//Programed by Michael<p>#include <iostream.h> //this means include imput/output stream
#include <ctype.h> //this makes the program able to use the toupper feature<p>main () //this is the main function<p>{
char letter, ans; //this says that letter and ans are characters<p>cout << "Programed By Michael
Class: Computer C++, RRHS
Instructor: Mr. H, Block 3
Program #1: Vowels, Consonants
";<p>do
{
cout << "Would you like to play the game?
"; //this is the initial question asking if you want to play
cout << "Enter Y or N & press enter!";
cin >> ans;//this take in the letter y or n
ans = toupper(ans); //this automatically takes the imput, ans in this case, and converts it to uppercase
switch (ans)
{
case 'Y': //this happens if you enter y
{
cout << "You have decided to play the game!
";
cout << "Enter a letter from A to Z & press enter!";
cin >> letter; //this takes in the imput of the letter
letter = toupper(letter); //this converts all imput to uppercase brfore it's read
if ((letter == 'A')||(letter == 'E')||(letter == 'I')||(letter == 'O')||(letter == 'U')) //this says that if letter is a,e,i,o, or u, certain actions will happen
{cout << "You have entered a vowel!
";} //this accounts for vowels
else
{cout << "You have entered a consonant!
";} // this accounts for consonants
break; //break stops the action from running
}
case 'N': //this happens if you enter n
cout << "Thanks for the character game!
";
break;
default://this happens if you enter an answer other than y or n
cout << "Follow the directions, try again, and press enter!
";
break;<p>}<p>}while((ans == 'Y')||(ans != 'N')); //this makes it repeat while the answer is y
return 0; //this is required at the end of all programs
}

Is This A Good Question/Topic? 0
  • +

Replies To: program problem

#2 runtime error  Icon User is offline

  • Lucky.Code
  • member icon

Reputation: 3
  • View blog
  • Posts: 629
  • Joined: 19-March 01

Re: program problem

Posted 03 February 2002 - 11:28 PM

well just take the
cout << "Would you like to play the game?
";  

and put it out of the loop.
but leave the cin in the loop.

Was This Post Helpful? 0
  • +
  • -

#3 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 04 February 2002 - 06:12 AM

that solves the problem, but after you enter a letter, and it tells you if it's a vowel, it's supposed to come back up and say "Would you like to play....".  How can i keep it in the loop but keep it out of the default error message?
Was This Post Helpful? 0
  • +
  • -

#4 dlkj  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 137
  • Joined: 11-March 02

Re: program problem

Posted 11 March 2002 - 02:03 AM

nested loops
Was This Post Helpful? 0
  • +
  • -

#5 Krillinwarrior  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-March 02

Re: program problem

Posted 11 March 2002 - 06:44 AM

What are you doing asking this on dreamincode anyways mike.  You should just ask me and i can help you in person. Its a pretty small error anyways.
Was This Post Helpful? 0
  • +
  • -

#6 tomrel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 171
  • Joined: 27-August 01

Re: program problem

Posted 11 March 2002 - 03:12 PM

come on david that's what this site if for.asking people over a larger area of knowlege. it's a resource for the people.
Was This Post Helpful? 0
  • +
  • -

#7 Krillinwarrior  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-March 02

Re: program problem

Posted 11 March 2002 - 03:27 PM

Sorry, i just thought it would have been faster and easier for him to ask me.  Anyways, i saw his program in class today and i am not sure what is causing the problem.  Probably because i didn't take a real close look at it.
Was This Post Helpful? 0
  • +
  • -

#8 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 11 March 2002 - 03:31 PM

i'm going to re-post my program in my thread 'prefix/postfix'... this is from a long time ago
Was This Post Helpful? 0
  • +
  • -

#9 Krillinwarrior  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-March 02

Re: program problem

Posted 11 March 2002 - 03:39 PM

Holly shit mike, why the heck are you still using a fucking switch statement to run your Y/N operation.  It is to big. Use if statements, much easier.
Was This Post Helpful? 0
  • +
  • -

#10 tomrel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 171
  • Joined: 27-August 01

Re: program problem

Posted 11 March 2002 - 03:41 PM

you know david they don't allow cussing in here.
Was This Post Helpful? 0
  • +
  • -

#11 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 11 March 2002 - 03:42 PM

david, this is an old post from a few pograms ago... i have a lot of old program posts in c++.  usually the one closest to the top is the newest.
Was This Post Helpful? 0
  • +
  • -

#12 Krillinwarrior  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 08-March 02

Re: program problem

Posted 11 March 2002 - 03:52 PM

oops, sorry mike, didn't realize, thought it was a recent one because it was near the top of the forum list
Was This Post Helpful? 0
  • +
  • -

#13 robarb  Icon User is offline

  • D.I.C Lover

Reputation: 2
  • View blog
  • Posts: 1,966
  • Joined: 31-January 02

Re: program problem

Posted 11 March 2002 - 03:53 PM

no prob... :smile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1