QAProgramming › Re-type the code and fix any errors. The code should convert non-positive numbers to 1.
Q

Re-type the code and fix any errors. The code should convert non-positive numbers to 1.

Re-type the code and fix any errors. The code should convert non-positive numbers to 1.

if (userNum > 0)

cout << "Positive." << endl;

else

cout << "Not positive, converting to 1." << endl;

userNum = 1;

cout << "Final: " << userNum << endl;

answer:

#include

using namespace std;

int main() {

int userNum;

cin >> userNum;

/* Your solution goes here */

return 0;

}

A

All you need to do here is to changes the lines order.

#include <iostream>

using namespace std;

int main()

{

int userNum;

cout<<“Enter a number”<<endl;

cin >> userNum;

if (userNum > 0){

cout << “Positive.” << endl;

}

else{

cout << “Not positive, converting to 1.” << endl;

userNum=1;

}

cout<<“Final: “<<userNum<<endl;

return 0;

}

3 years ago
161 Views