alslam wa alykom
Can anyone help me to stop this program by using sentinel-controlled loop? It is for my project in the
university
Sorry for not writing in Arabic
// husam
[CODe2]
import javax.swing.JOptionPane;
public class QuizProgram
{
public static void main( String args[] )
{
String firstQuestion,
secondQuestion,
thiredQuestion,
fourthQuestion;
int answer1,//answer qution1 by user
answer2,// answer question2
answer3,//answer question
answer4; // answer question
int sentinel =0;
do{
firstQuestion=JOptionPane.showInputDialog(null, "How many oceans are they in world? ");
answer1 =Integer.parseInt( firstQuestion );
if(answer1==4)
JOptionPane.showMessageDialog(null,"The answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong you should try again");
}while(answer1!=4);
do{
secondQuestion=JOptionPane.showInputDialog(null, " How many stats in USA? ");
answer2 =Integer.parseInt( secondQuestion );
if(answer2==50)
JOptionPane.showMessageDialog(null,"your answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong");
}while(answer2!=50);
do{
thiredQuestion=JOptionPane.showInputDialog(null, " How many countries in Europe? ");
answer3 =Integer.parseInt( thiredQuestion );
if(answer3==12)
JOptionPane.showMessageDialog(null,"your answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong you should try again");
}while(answer3!=12);
do{
fourthQuestion=JOptionPane.showInputDialog(null, "How many continents in the world? ");
answer4 =Integer.parseInt( fourthQuestion );
if(answer4==6)
JOptionPane.showMessageDialog(null,"your answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong");
}while(answer4!=6);
}
}
[/CODe2]
thank you
// husam
[CODe2]
import javax.swing.JOptionPane;
public class QuizProgram
{
public static void main( String args[] )
{
String firstQuestion,
secondQuestion,
thiredQuestion,
fourthQuestion;
int answer1,//answer qution1 by user
answer2,// answer question2
answer3,//answer question
answer4; // answer question
int sentinel =0;
do{
firstQuestion=JOptionPane.showInputDialog(null, "How many oceans are they in world? ");
answer1 =Integer.parseInt( firstQuestion );
if(answer1==4)
JOptionPane.showMessageDialog(null,"The answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong you should try again");
}while(answer1!=4);
do{
secondQuestion=JOptionPane.showInputDialog(null, " How many stats in USA? ");
answer2 =Integer.parseInt( secondQuestion );
if(answer2==50)
JOptionPane.showMessageDialog(null,"your answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong");
}while(answer2!=50);
do{
thiredQuestion=JOptionPane.showInputDialog(null, " How many countries in Europe? ");
answer3 =Integer.parseInt( thiredQuestion );
if(answer3==12)
JOptionPane.showMessageDialog(null,"your answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong you should try again");
}while(answer3!=12);
do{
fourthQuestion=JOptionPane.showInputDialog(null, "How many continents in the world? ");
answer4 =Integer.parseInt( fourthQuestion );
if(answer4==6)
JOptionPane.showMessageDialog(null,"your answer is correct");
else
JOptionPane.showMessageDialog(null,"your answer is wrong");
}while(answer4!=6);
}
}
[/CODe2]