The following program contains errors. Correct them so that the program will run
ID: 3684966 • Letter: T
Question
The following program contains errors. Correct them so that the program
will run and output w = 21.
#include <iostream>
using namespace std;
const int SECRET = 5
main ()
{
int x, y, w, z;
z = 9;
if z > 10
x = 12; y = 5, w = x + y + SECRET;
else
x = 12; y = 4, w = x + y + SECRET;
cout << "w = " << w << endl;
The following program contains errors. Correct them so that the program
will run and output w = 21.
#include <iostream>
using namespace std;
const int SECRET = 5
main ()
{
int x, y, w, z;
z = 9;
if z > 10
x = 12; y = 5, w = x + y + SECRET;
else
x = 12; y = 4, w = x + y + SECRET;
cout << "w = " << w << endl;
Explanation / Answer
Answer:
#include<iostream>
#include<conio.h>
using namespace std;
const int SECRET = 5;
int main ()
{
int x, y, w, z;
z = 9;
if (z > 10)
{
x = 12, y = 5, w = x + y + SECRET;
}
else
{
x = 12; y = 4, w = x + y + SECRET;
cout << "w = " << w << endl;
}
_getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.