Missing Output

This is a discussion on Missing Output within the C++ Programming forums, part of the General Programming Boards category; I've inputted a sting (a name) and also inputted a number. However, when this runs the second time (Twice per ...

  1. #1
    Unregistered
    Guest

    Missing Output

    I've inputted a sting (a name) and also inputted a number. However, when this runs the second time (Twice per program, usually), the second person's stats do not appear when couted. Can someone help?

    Code:
    #include <iostream.h>
    
    main()
    {
    	int Loop;
    	do
    	{
    		char OneName[21], TwoName[21], Choice;
    		int OneHealth, TwoHealth;
    		cout << '\n';
    		cout << "What is Player 1's name? (20 char. max) ";
    		cin.get(OneName, 21);
    		cin.ignore(5, '\n');
    		do
    		{
    			cout << '\n' << "How much life does " << OneName << " have? (Range: 150-500) ";
    			cin >> OneHealth;
    		}
    		while ((OneHealth < 150) || (OneHealth > 500));
    		cout << '\n';
    	
    		cout << '\n';
    		cout << "What is Player 2's name? (20 char. max) ";
    		cin.get(TwoName, 21);
    		cin.ignore(5, '\n');
    		do
    		{
    			cout << '\n' << "How much life does " << TwoName << " have? (Range: 150-500) ";
    			cin >> TwoHealth;
    		}
    		while ((TwoHealth < 150) || (TwoHealth > 500));
    		cout << '\n';
    	
    		cout << OneName << " has " << OneHealth << " health and " << TwoName << " has " << " health." << endl;
    		cout << "Is this correct? (Y/N) ";
    		cin >> Choice;
    		if ((Choice == 'Y') || (Choice == 'y'))
    			Loop = 10;
    	}
    	while (Loop != 10);
    	return 0;
    }
    BTW, is there a way to use a CLS-like command (like in QBASIC and DOS) in C++?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    try using getline() instead of get() if the name can have a space in it and moving the calls to ignore() so they are immediately after the use of statements with >> rather that the statements with getline()

  3. #3
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    I think one way to do CLS is:
    Code:
    SYSTEM("cls");
    You have to include stdlib.h I think....
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  4. #4
    Unregistered
    Guest
    Originally posted by guest
    try using getline() instead of get() if the name can have a space in it and moving the calls to ignore() so they are immediately after the use of statements with >> rather that the statements with getline()
    Do you mean couting the stuff right there? I'll try it.

    ski6ski, thanks but you didn't need to reply. It was in the Board FAQ, which I should have checked again before posting. Thanks anyway.

  5. #5
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Sometimes people who log in as " Unregistered" or "Guest" do not take the time to look in the FAQ, so instead of ranting on using the FAQ, I just put it there for you. Not saying anything bad about you, at least you did use the FAQ! Thx.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  6. #6
    Unregistered
    Guest
    Umm...odd. Neither the clrscr() or the one you gave above work. I'm sure I included conio.h and stdlib.h for the respective ones, and I don't really get the other ones in the FAQ. Can someone help?

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    what operating system?

    The windows console version of clrscr() is in the FAQ
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    Unregistered
    Guest
    Yeah, it's Win98 with VC++ 5.0. It's still not working, though. It keeps thinking that clrscr()'s a variable or function, even with conio.h.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 02:08 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  5. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 12:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21