printing out selected items only

This is a discussion on printing out selected items only within the C++ Programming forums, part of the General Programming Boards category; I have tried everything I can think of. I can not figure out how to check to see if an ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    7

    printing out selected items only

    I have tried everything I can think of.

    I can not figure out how to check to see if an item has been selected.
    do I need to create a return value function to have the program keep track of the items selected?

    Code:
    while ((answer == 'y' || answer == 'Y') && (ICounter <= noOfItems))
    		{
    		ICounter++;
    		cout << "Enter item number from Menu: ";
    		cin >> menuList[i].choices;
    if ( menuList[i].choices == menuList[i].choices) 
    				{
    				cout << "Do you want to make another selection? Y/y (Yes) or any other key for No: ";
    				cin >> answer;
    				}
    				else 
    				{
    				cout << "*** This Item has been selected ***" << endl;
    				cout << "Do you want to make another selection? Y/y (Yes) or any other key for No: ";
    				cin >> answer;
    				}
    		}		
    		}

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    One optiion is to use the default value of an array's element to determine if selection was already made. Have the elements index number correlate with the selection number somehow. Something similar to this might work:
    Code:
    //use an array to keep track of items selected
    //initialize elements to a default value
    int array[noOfItems] = {defaultValue};   
     
    //get users selection of options from a menu
    enter choice from menu
    1) foo
    2) bar
    get choice
     
    //determine if selection made already
    if array[choice - 1] equals the default value
      change value array element to indicate item selected
      increase counter of unique selections
    else
      you've selected this item already
    	  
    You can then use the array's information to output inforamtion about what selections were made.
     
    //start output loop here
    you chose items :
    if array[i] not equal to defaultValue
      output index value + 1
    from the following selection options:
    1) foo
    2) bar
    //stop output loop here
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 07:41 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 08:35 AM
  3. Create new combo boxes based on items selected in preview combo box
    By RealityFusion in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2007, 09:50 AM
  4. Printing all items in a Queue
    By Zildjian in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2004, 02:25 PM
  5. Selected Items in a ListView
    By Lowas in forum Windows Programming
    Replies: 12
    Last Post: 09-01-2001, 08:17 PM

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