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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

Part 4:

Working with Logic Errors:

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 <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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage