Working with Logic Errors // This program takes two values from the user and then swaps them // before printing the values. The user will be prompted to enter // both numbers. // Place your name here #include using namespace std; int main() { float firstNumber; float secondNumber; // Prompt user to enter the first number. cout << "Enter the first number" << endl; cout << "Then hit enter" << endl; cin >> firstNumber; // Prompt user to enter the second number. cout << "Enter the second number" << endl; cout << "Then hit enter" << endl; cin >> secondNumber; // Echo print the input. cout << endl << "You input the numbers as " << firstNumber << " and " << secondNumber << endl; // Now we will swap the values. firstNumber = secondNumber; secondNumber = firstNumber; // Output the values. cout << "After swapping, the values of the two numbers are " << firstNumber << " and " << secondNumber << endl; return 0; } Exercise 2: Compile this program. You should get no syntax errors. Exercise 3: Run the program. What is printed? Exercise 4: This program has no syntax or run time errors, but it certainly has a logic error. This logic error may not be easy to find. Most logic errors create a challenge for the programmer. Your instructor may ask you not to worry about finding and correcting the problem at this time.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Part 4:
Working with Logic Errors:
Working with Logic Errors
// This
// before printing the values. The user will be prompted to enter
// both numbers.
// Place your name here
#include <iostream>
using namespace std;
int main()
{
float firstNumber;
float secondNumber;
// Prompt user to enter the first number.
cout << "Enter the first number" << endl;
cout << "Then hit enter" << endl;
cin >> firstNumber;
// Prompt user to enter the second number.
cout << "Enter the second number" << endl;
cout << "Then hit enter" << endl;
cin >> secondNumber;
// Echo print the input.
cout << endl << "You input the numbers as " << firstNumber
<< " and " << secondNumber << endl;
// Now we will swap the values.
firstNumber = secondNumber;
secondNumber = firstNumber;
// Output the values.
cout << "After swapping, the values of the two numbers are "
<< firstNumber << " and " << secondNumber << endl;
return 0;
}
Exercise 2: Compile this program. You should get no syntax errors.
Exercise 3: Run the program. What is printed?
Exercise 4: This program has no syntax or run time errors, but it certainly has a
logic error. This logic error may not be easy to find. Most logic errors
create a challenge for the programmer. Your instructor may ask you not to
worry about finding and correcting the problem at this time.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps