Hai ! I really need a help about sentinel while. tbh I still cant get idea how sentinel working. here's the Q :
two numbers are taken for evaluation.
while first number is equal to 10 AND the second number is not equal to 10.The computer will continue asking user to give new number.When both number meet the criteria ,computer will end the program.
my coding:
#include<iostream>
using namespace std;
int main()
const int SENTINEL=10;
{//opening for int main
//declare identifier
int num1;
int num2;
//input
cout<<"Enter number 1 : ";
cin>>num1;
cout<<"Enter number 2 ; " ;
cin>>num2;
while(num1==SENTINEL&&num2!=SENTINEL)
{//opening for if
if(num1==10&&num2!=10)
cout<<"COngratulation.";
}//closing for if
else
{//opening for else
cout<<"Please try again! ";
}//closin for elseg
return 0;
}//closing for int main
I hope someone can make a clear for me.Thank you :)
You should put the cin inside the beginning of the while, and ALWAYS initialize ints to be at least 0. But if you want to be more formal, you could initialize it as -1 as undefined.