Results 1 to 10 of 10
  1. Default C++ Programming help needed

    Hi all~
    I'm having a little trouble coming up with a program for this problem I was assigned. Here is the problem:

    A minivan has two sliding doors. Each door can be opened by either a dashboard switch, its inside handle or its outside handle. However, the inside handles do not work if a child lock switch is activated, in order for the sliding doors to open, the gear shift must be in park and the master unlock switch must be activated.
    Your task is to simulate a portion of the control software for the vehicle. The input is a sequence of values for the switches and the gear shift, in the following order:
    - Dashboard switches for left and right sliding door, child lock and mast lock (0 for off and 1 for activated).
    - Inside and outside hands on the left and right doors (1 and 0).
    - The gear shift setting (one of P N D 1 2 3 R).

    Typical input would be 0 0 0 1 0 1 0 0 P

    Print “Left door opens” and/or “right door opens” as appropriate. If neither door opens, print “both doors stay closed.”

    So far I have asked for input for the nine boolean things. I'm having trouble coming up with some if and if/else statements. It's quite tough to organize all these combinations and stuff. Anyway, any help would be much appreciated!

    Also, sorry for the block of text

  2. Default Re: C++ Programming help needed

    Why not use a switch statement instead of a bunch of chain if/then statements? If you have only 9 boolean combinations that are correct that is.

  3. Default Re: C++ Programming help needed

    Err, I haven't had any practice with switch statements in class. I'll go over my notes on it and look in the book to see if I can figure it out doing that!

  4. Nuclear testing facility Straight Male
    IGN: VerrKol
    Server: Zenith
    Level: 204
    Job: Bowmaster
    Guild: LegacyReborn
    Farm: Kolville

    Default Re: C++ Programming help needed

    You need a hierarchy of switches. The order should be based on Venn-diangram style possibilities or you can draw the classic logic diagram.

    Something like

    if (master = 0)
      if (gear = P)
       if (inside stuff) {}
       if (outsides stuff) {}
       if (dashboard stuff) {}//not necessarily in this order

  5. Default Re: C++ Programming help needed

    Hmm okay! I feel like this could get very long and messy. Could you maybe give me an example of using a switch statement instead of nested if's?

  6. Default Re: C++ Programming help needed

    Okay, there are 8 booleans and 1 char.

    So you need to have a few objects:

    A minivan object which HAS A:
    - driver door (Door class)
    - passenger door (Door class)
    - left sliding door (Sidedoor class - subclass of a Door)
    - right sliding door (Sidedoor class - subclass of a Door)

    The minivan object HAS A constructor which you pass the initial string to. The constructor parses this information and sets the state of the minivan.

    Then, in the minivan, you can ask it questions:
    So you can fetch state from these objects.

    It will be a lot of methods and classes, but it should all be fairly logical.

  7. Default Re: C++ Programming help needed

    All of you are so good at this stuff and I'm sitting over here like "derp, what is ASCII, derp". But okay guys, I think you gave me enough info to get this program going. I might be back later tonight needing help. Thank you once again!

  8. Default Re: C++ Programming help needed

    so right now I have:
    	//Declare objects
    	bool dashboard_switch_left, dashboard_switch_right, child_lock, left_inside_handle, left_outside_handle, right_inside_handle, right_outside_handle, master_lock, gear;
    	//Ask user for input
    	cout << "Enter value for left dashboard switch (1=activated, 0=off): " << endl;
    	cin >> dashboard_switch_left;
    	cout << "Enter value for the right dashboard switch (1=activated, 0=off): " << endl;
    	cin >> dashboard_switch_right;
    	cout << "Enter value for Child Lock (1=activated, 0=off): " << endl;
    	cin >> child_lock;
    	cout << "Enter value for inside left handle (1=activated, 0=ff): " << endl;
    	cin >> left_inside_handle;
    	cout << "Enter value for outside left handle (1=activated, 0=ff): " << endl;
    	cin >> left_outside_handle;
    	cout << "Enter value for inside right handle (1=activated, 0=ff): " << endl;
    	cin >> right_inside_handle;
    	cout << "Enter value for outside right handle (1=activated, 0=ff): " << endl;
    	cin >> right_outside_handle;
    	cout << "Enter value for Master Lock (1=activated, 0=off): " << endl;
    	cin >> master_lock;
    	cout << "Enter value for gear (P=1, N,D,1,2,3,R=0): " << endl;
    	cin >> gear;
    	if (master_lock=0)
    		if (child_lock=0)
    			if (gear=1)
    				if	(dashboard_switch_left=0) {}
    					if (left_inside_handle=0) {}
    						if (left_outside_handle=0)
    						cout << "Left door opens" << endl;
    	return 0;
    I can't seem to get the "Left Door Opens" to pop up after entering the correct values….can you tell me what I'm doing wrong?

  9. Orbital Bee Cannon
    IGN: SaptaZapta
    Server: Kradia
    Level: 214
    Job: Hero
    Guild: Matriarchy
    Alliance: Dominion

    Default Re: C++ Programming help needed

    Use == instead of =

    You are assigning rather than comparing (in the "if" statements).

  10. Default Re: C++ Programming help needed

    Figured that out the hard way! haha I got the program fully written and working now. thanks!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts