+ 2

Can anyone show me some examples of c++ programs using while loop and if else at once?

21st Dec 2018, 2:19 AM
Tecolote Come Elote
Tecolote Come Elote - avatar
5 odpowiedzi
21st Dec 2018, 2:29 AM
deeyae
deeyae - avatar
+ 2
The if / else are conditional statements, giving your program conditions for instance using the if / else statement you can make a program that determines whether someone is an adult or a child... look at this: please note that the general syntax of if statement is this: if(condition){ statement } else{ statement } example: #include <iostream> using namespace std; int a; int main(){ cout<<"Enter your age to determine whether you are an adult or a child"<<endl; cin>>a; if (a<18){ cout<<"You are a child."<<endl; } else{ cout<<"You are an adult."<<endl; }
21st Dec 2018, 6:01 AM
Jacob Chikwanda
Jacob Chikwanda - avatar
+ 1
while loop can be used to determine numbers that are say "less than 10" for example general syntax is: while (condition) { statement } example #include <iostream> using namespace std; int a=1; int main(){ while (a<6){ cout<<"this number is less than 6: "<<a<<endl; a++ or a=a+1; } return 0 } you will have five outputs...
21st Dec 2018, 6:07 AM
Jacob Chikwanda
Jacob Chikwanda - avatar
+ 1
While (conditions) {if (condition) { ....... ...... } else { ........ ...... } }
22nd Dec 2018, 4:19 PM
Subharthi Paul
0
Thanks bro
21st Dec 2018, 6:09 AM
Tecolote Come Elote
Tecolote Come Elote - avatar