1) Given the following code, write a conditional logic statement that that evalu
ID: 3532678 • Letter: 1
Question
1) Given the following code, write a conditional logic statement that that evaluates to true if userInput is on [24, 36] and also odd.
#include <iostream>
using namespace std;
int main() {
int userInput = 0;
cout << "Please type in an integer and press enter: ";
cin >> userInput;
if( /* your condition */) {
cout << "The statement was true...";
}
return 0;
}
2) Given the following code, write a conditional logic statement that evaluates to true if userInput is divisible by 3 and 7.
#include <iostream>
using namespace std;
int main() {
int userInput = 0;
cout << "Please type in an integer and press enter: ";
cin >> userInput;
if( /* your condition */) {
cout << "The statement was true...";
}
return 0;
}
3) Given the following code, write a conditional logic statement that evaluates to true if userInput is not equal to 22 or 24 and even.
#include <iostream>
using namespace std;
int main() {
int userInput = 0;
cout << "Please type in an integer and press enter: ";
cin >> userInput;
if( /* your condition */) {
cout << "The statement was true...";
}
return 0;
}
PLEASE ANSWER THE 3 QUESTIONS ABOVE USING THE GIVEN CODE AND INFORMATION IN EACH QUESTION.
Explanation / Answer
1.
#include <iostream>
using namespace std;
int main() {
int userInput = 0;
cout << "Please type in an integer and press enter: ";
cin >> userInput;
if( (userInput>24)&&(userInput<36)) {
cout << "The statement was true...";
}
else if((userInput)%2!=0){
cout<<"The statement was true...";
return 0;
}
2.
#include <iostream>
using namespace std;
int main() {
int userInput = 0;
cout << "Please type in an integer and press enter: ";
cin >> userInput;
if(((userInput)%3==0)&&((userInput)%7==0)) {
cout << "The statement was true...";
}
return 0;
}
3.
#include <iostream>
using namespace std;
int main() {
int userInput = 0;
cout << "Please type in an integer and press enter: ";
cin >> userInput;
if( (userInput!=22) !! (userInput!=24) ) {
cout << "The statement was true...";
}
else if((userInput)%2==0){
cout << "The statement was true...";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.