CS 101 homework help
$-1-4 USD
Bezahlt bei Lieferung
Need help with basic cpp.
I need an explanation of this code:
================================================
switch ( menuOption) {
case 1: planetWeight = earthWeight * 0.39; // Mercury
break;
case 2: planetWeight = earthWeight * 0.91; // Venus
break;
case 3: planetWeight = earthWeight * 0.38; // Mars
break;
default: planetWeight = earthWeight - 1; // Earthweight - 1
// People like to think they're losing weight (marketing)
break;
}
cout << " Your new weight is " << planetWeight "\n";
// Now illustrating the continue statement
int firstNumber, secondNumber;
for ( ; ; ) { // Begin infinite loop
cout<< "Enter two integers, where we will divide the first by the second: ";
cin>> firstNumber >> secondNumber;
if ( secondNumber == 0 ) {
continue; // Try again, as division by 0 is problematic
}
cout<< firstNumber << " / " << secondNumber << " = " << firstNumber/secondNumber << "\n;
}
cout<< "You will never see this secret message. My locker combination is: 22-46-19.";
return 0;
}
=====================================================
1) firstNumber and secondNumber are ints:
will the result be an int or a decimal?
2)how can I make sure it shows as decimal?
3) if I erase the break; 's from the switch, the
program gives output, but doesn't work right.
If I erase all the breaks will it perform the last
case or the default?
4) Why does for(;;) actully loop?
Is it possible to do empty loops with while too?
Why use empty loops?
Projekt-ID: #3921433