Question
Exercise 1: conditional executions Complete the following program by writing C++ statements that correspond to the description in each comment in the code. Make sure
Exercise 1: conditional executions
Complete the following program by writing C++ statements that correspond to the description in each comment in the code. Make sure all output to the screen has newlines after it.
#include
#include
using namespace std;
int main()
{
// declare a variable to hold a character and initialize it
// to the letter H
// print "The value of the variable is
// prompt the user to enter a value
// store whatever character the user types in your variable
// if the user typed W print "Excellent. "
// otherwise print, "No, you fool! "
return 0;
}
Exercise 2: conditional loops
1. How many times does the following loop execute? What is the value of the variable i after the loop is done?
int i = 1;
while( i < 10 )
{
i = i + 2;
}
2. What is the output of the following C++ code?
int count = 1;
int y = 100;
while ( count < 100 )
{
y = y - 1;
count++;
}
cout << "y = " << y << " and count = " << count << endl;
3. Given a double variable n, write C++ statements to ask the user to enter a real number repeatedly until the user enters a number that is greater than n. Store the user number in a double variable number.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started