+ 2
Can anyone show me some examples of c++ programs using while loop and if else at once?
5 odpowiedzi
+ 3
May be this can help you :
https://code.sololearn.com/cj0cW05isjTB/?ref=app
+ 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;
}
+ 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...
+ 1
While (conditions)
{if (condition)
{ .......
......
}
else
{ ........
......
}
}
0
Thanks bro