HELP NEEDED ASAP PLEASE DEBUGGING The code below has five er
HELP NEEDED ASAP PLEASE.
DEBUGGING
The code below has five errors. The errors may be syntax errors or logic errors, and there may be more than one per line; examine the code carefully to find them. Indicate each of the errors you find by writing the line number and correction in the space provided below.
You must find and correct all five of the errors.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;
int main()
{
int num;
bool prime = true;
cout << \"This program determines if a \" << \"number is prime\" endl;
// for this program, 0 does not count as positive
while (num <= 0) {
cout << \"Enter a positive number: \";
cin << num;
}
for(int i = 1; i < num; i++) {
if (num % i == 0) {
prime = false;
}
}
if (prime = true) {
cout << \"The number \" << num << \" is prime.\" << endl;
}
else if {
cout << \"The number \" << num << \" is not prime.\" << endl;
}
}
Line Number
Correction
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> using namespace std; int main() { int num; bool prime = true; cout << \"This program determines if a \" << \"number is prime\" endl; // for this program, 0 does not count as positive while (num <= 0) { cout << \"Enter a positive number: \"; cin << num; } for(int i = 1; i < num; i++) { if (num % i == 0) { prime = false; } } if (prime = true) { cout << \"The number \" << num << \" is prime.\" << endl; } else if { cout << \"The number \" << num << \" is not prime.\" << endl; } } |
Solution
Hi
I have fixed the issues and highlighted the code changes below.
#include <iostream>
using namespace std;
int main()
{
int num = 0;
bool prime = true;
cout << \"This program determines if a \" << \"number is prime\"<< endl;
// for this program, 0 does not count as positive
while (num <= 0) {
cout << \"Enter a positive number: \";
cin >> num;
}
for(int i = 2; i < num; i++) {
if (num % i == 0) {
prime = false;
}
}
if (prime == true) {
cout << \"The number \" << num << \" is prime.\" << endl;
}
else {
cout << \"The number \" << num << \" is not prime.\" << endl;
}
}
Output:
This program determines if a number is prime
Enter a positive number: 17
The number 17 is prime.
Line Number
Correction
| Line Number | Correction |
| 7 | \"number is prime\"<< endl; |
| 5 | int num = 0; |
| 11 | cin >> num; |
| 13 | for(int i = 2; |



