Programming and Graphics

(Kiana) #1

54 Introduction to C++ Programming and Graphics


b=a+3;
c=20;
}
else
{
cout << "angouraki" << endl;
}

The statement

cout << "angouraki" << endl;

prints the word “angouraki” on the screen and moves the cursor to the
next line.


  • if/else if structure:


Theif/else ifstructure implements conditional execution based on
several options.

For example, we may write:

if(a==1)
{
b=a+3;
c=20;
}
else if (a==2.3)
{
cout<<"angouraki"<<endl;
}
else
{
cout<<"maintanos"<<endl;
}

We can use multipleelse ifblocks and skip the lastelseblock. If
two options coincide, the first-encountered option will be executed before
exiting the structure.

Note thatelseandifare two separate words separated by white space.
InMatlab, these two words are merged into the ungrammaticalelseif.


  • switch structure:


Consider an integer or character variable,diosmos.Ifdiosmos=n 1
Free download pdf