Please, no arrays or for statements. Just simply while and if statements Also I
ID: 3528948 • Letter: P
Question
Please, no arrays or for statements. Just simply while and if statements
Also I dont require you to write a program, just an tips or hints in everyday lingo can help to. I'm just stuck!
Essentially this is what I want the program to do:
1. Ask the user to enter two variables (a and b). And continuously ask user for 2 inputs until 99 99 is entered (so BOTH a = 99 and b=99)
2. Then once user has inputted two consecutive inputs. So (12 15, 12 17) I want to calculate the difference between these two (so 2)
3. HERES the hard part for me: The only valid inputs the user should put in should be (0<=a<24 0<=b<60). If they put anything outside that it should be discarded data. Also if the entry after is < entry before then that's also considered data
Examples:
Enter 24hr time (99 99 to exit): 99 99
[program stops]
Enter 24hr time (99 99 to exit): 54 3
invalid entry
Enter 24hr time (99 99 to exit): 12 34
Enter 24hr time (99 99 to exit): 12 12
invalid entry
Enter 24hr time (99 99 to exit): 12 50
[loop stops]
[displays gap between 1234 and 1250]
Explanation / Answer
Answer-1
do{
cin>>a>>b;
}while(a!=99 || b!=99);
Answer-2
tempa=0;
tempb=0
do{
cin>>a>>b;
if(tempa!=0 && tempb!=0)
{
if(a>tempa && b>tempb)
{
diffA=a-tempa;
diffB=b-tempb;
cout<<diffA<<" "<<diffB
}
}
tempa=a;
tempb=b;
}while(a!=99 || b!=99);
Answer-3
tempa=0;
tempb=0
do{
cin>>a>>b;
if((a>12 || a<0) || (b>60 || b<0)|| a<tempa || b<tempb)
{
cout<<"invalid entry ";
}
else{
if(tempa!=0 && tempb!=0)
{
if(a>tempa && b>tempb)
{
diffA=a-tempa;
diffB=b-tempb;
cout<<diffA<<" "<<diffB
}
}
tempa=a;
tempb=b;
}
}while(a!=99 || b!=99);