Complete this program, prompting the user to to enter two positive numbers a and b so that a is less than b. #include <iostream> using namespace std; int main() { int a, b; /* Your code goes here */ cout << "Enter two positive integers, the first smaller than the second." << endl; cout << "First: " << endl; cin >> a; cout << "Second: " << endl; cin >> b; /* Your code goes here */ }
Added by Robert F.
Close
Step 1
This can be done using a `while` loop. Show more…
Show all steps
Your feedback will help us improve your experience
Aarya B and 101 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
(C++) Write programs for the following (VS17 Express) Consider the following program in which the statements are in the incorrect order: Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Format the output to two decimal places. #include <iostream> #include <iomanip> #include <cmath> const double PI = 3.14159; int main() { double height, radius; cout << "Enter the height of the cylinder: "; cin >> height; cout << endl; cout << "Enter the radius of the base of the cylinder: "; cin >> radius; cout << endl; cout << fixed << showpoint << setprecision(2); cout << "Volume of the cylinder = " << PI * pow(radius, 2.0) * height << endl; cout << "Surface area: " << 2 * PI * radius * height + 2 * PI * pow(radius, 2.0) << endl; return 0; }
Akash M.
What is the output of the below program? int main() { int a = 10; cout << a++; return 0; }
Paul G.
CHALLENGE ACTIVITY 3.17.1: Conditional expression: Print negative or positive. Create a conditional expression that evaluates to the string "negative" if userVal is less than 0, and "non-negative" otherwise. Ex: If userVal is -9, the output is: "negative". #include <iostream> #include <string> using namespace std; int main() { string condstr; int userVal; cin >> userVal; condstr = (userVal < 0) ? "negative" : "non-negative"; cout << userVal << " is " << condstr << endl; return 0; }
Liam H.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD