Here is the question in its entirety but the actual problem

Here is the question in its entirety, but the actual problem is at the end. I just felt that I would give an overview of what I am asking. The program has to be in c++ (.cpp) and must compile as such. I use linux.

Conditionals

The if-else statement

Example:

  1 if( a > 5)

2   cout << \"That\'s a large number!\" << endl;

Optionally, you may also have an else:

1 if( a > 5)

2   cout << \"That\'s a large number!\" << endl;

3 else

4   cout << \"Large? Not so much.\" << endl;

The if-clause and else-clause work only with single statements (lines 2 & 4). If you would like either the if-clause or the else-clause to work with more than one statement then you must surround those statements with curly braces. For example, if line 2 above was broken into two lines:

  1 if( a > 5)

2 {

3   cout << \"That\'s a \";

4   cout <<<\"large number!\" << endl;

5 }

6 else

7   cout << \"Large? Not so much.\" << endl;

The same requirement for curly braces applies to the statement following the else-clause as well:

  1 if( a > 5)

2   cout << \"That\'s a large number!\" << endl;

3 else

4 {

5   cout << \"Large? \";

6   cout << Not so much.\" << endl;

7 }

Note: Most operators in C++ are easily understood. For example, < is less-than, >= is greater than or equal-to, etc. However, less intuitive are these two operators:

=  This operator means \"assignment\". For example, a=5 means assign the number five to the variable \'a\'

== This operator means \"comparison for equality\". For example, a==5 means \"Are the contents of \'a\' equal to five?\"

Compound expressions

More than one boolean expression can be combined with the && (\"and\") and || (\"or\") operators. Examples:

  1 if( play_again == \'y\' || play_again == \'Y\')

  

  1 if( one_thru_ten => 1 && one_thru_ten <= 10)

Using if/else statements

Write a program used by the Department of Motor Vehicles (DMV) to teach learning drivers how to behave at an intersection. Proper driving follows the following table:

Example program input and output:

What direction are you driving (right, left, straight)?

right

What color is the light (red, green)?

red

Go after stop.

direction light behavior
straight red Stop
straight green Go
right red Go after stop
right green Go
left red Stop
left green Go

Solution

#include<iostream.h>

#include<conio.h>

void main()

{

char dir,light,str,left,right,red,green;

cout<<\"what direction are you driving\"<<\"\ \";

cin>>dir;

cout<<what color is the light\"<<\"\ \";

cin>>light;

if(dir=str && light==red)

{

cout<<\"stop\"<<\"\ \";

}

else if(dir=str && light=green)

{

cout<<\"GO\"<<\"\\N\";

}

else if(dir=right && light=red)

{ cout<<\"Go after stop\"<<\"\ \"

}

else if(dir=right && light=green)

{

cout<<\"GO\"<<\"\\N\";

}.

cout<<\"Stop\"<<\"\ \";

}

else if(dir=left && light=red)

{cout<<\"Stop\"<<\"\ \";

}

else if(dir=left && light=green)

{ cout<<\"Go\"<<\"\ \";

}

else

cout<<\"select proper direction and light\"<<\"\ \";

cout<<\"===================Thank you=============\";

getch();

}

Here is the question in its entirety, but the actual problem is at the end. I just felt that I would give an overview of what I am asking. The program has to be
Here is the question in its entirety, but the actual problem is at the end. I just felt that I would give an overview of what I am asking. The program has to be
Here is the question in its entirety, but the actual problem is at the end. I just felt that I would give an overview of what I am asking. The program has to be

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site