Part 2 Compiling a Program with a Syntax Error Exercise 1: Bring in program semiprob.cpp from the Lab 1 folder. Exercise 2: Compile the program. Here we have our first example of the many syntax errors that you no doubt will encounter in this course. The error message you receive may be different depending on the system you are using, but the compiler insists that a semicolon is missing somewhere. Unfortunately, where the message indicates that the problem exists, and where the problem actually occurs may be two different places. To correct the problem place a semicolon after the line cout << "Today is a great day for Lab" . Most syntax errors are not as easy to spot and correct as this one. Exercise 3: Re-compile the program and when you have no syntax errors, run the program and input 9 when asked. Record the output. Exercise 4: Try running it with different numbers. Record your output. Do you feel you are getting valid output? The code of semiprob.cpp is as follows: // This program demonstrates a compile error. // Place your name here #include using namespace std; int main() { int number; float total; cout << "Today is a great day for Lab" cout << endl << "Let's start off by typing a number of your choice" << endl; cin >> number; total = number * 2; cout << total << " is twice the number you typed" << endl; return 0; }
Addition of Two Numbers
Adding two numbers in programming is essentially the same as adding two numbers in general arithmetic. A significant difference is that in programming, you need to pay attention to the data type of the variable that will hold the sum of two numbers.
C++
C++ is a general-purpose hybrid language, which supports both OOPs and procedural language designed and developed by Bjarne Stroustrup. It began in 1979 as “C with Classes” at Bell Labs and first appeared in the year 1985 as C++. It is the superset of C programming language, because it uses most of the C code syntax. Due to its hybrid functionality, it used to develop embedded systems, operating systems, web browser, GUI and video games.
Part 2
Compiling a
Exercise 1: Bring in program semiprob.cpp from the Lab 1 folder.
Exercise 2: Compile the program. Here we have our first example of the many
syntax errors that you no doubt will encounter in this course. The error
message you receive may be different depending on the system you are
using, but the compiler insists that a semicolon is missing somewhere.
Unfortunately, where the message indicates that the problem exists, and
where the problem actually occurs may be two different places. To correct
the problem place a semicolon after the line cout << "Today is a great
day for Lab"
.
Most syntax errors are not as easy to spot and correct as this one.
Exercise 3: Re-compile the program and when you have no syntax errors, run
the program and input 9 when asked. Record the output.
Exercise 4: Try running it with different numbers. Record your output.
Do you feel you are getting valid output?
The code of semiprob.cpp is as follows:
// This program demonstrates a compile error.
// Place your name here
#include <iostream>
using namespace std;
int main()
{
int number;
float total;
cout << "Today is a great day for Lab"
cout << endl << "Let's start off by typing a number of your choice" << endl;
cin >> number;
total = number * 2;
cout << total << " is twice the number you typed" << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images