I am having issues with C++ because this code does not work:int main() {int userNum;userNum = 5;cout << "Foretelling is hard." << endl;cout << "Particularly of the future." << endl;cout << "User num is:" << userNum << endl;/* Your solution goes here */return 0;Please tell me what to do with this line of code.

Question
Asked Sep 5, 2019
39 views

I am having issues with C++ because this code does not work:

int main() {
int userNum;

userNum = 5;
cout << "Foretelling is hard." << endl;
cout << "Particularly of the future." << endl;
cout << "User num is:" << userNum << endl;
/* Your solution goes here */

return 0;

Please tell me what to do with this line of code.

check_circle

Expert Answer

Step 1

Explanation:

  • A proper C++ program should include header file “<iostream>”, begins with “#” sign.
  • This header file allows the program to perform standard input and output operations.
  • The program should include the proper beginning and closing of main’s function definition.
  • It should also include standard namespace “std”, which defines the standard character input and output device such as “cout” and “cin”.
  • The given code is not included the header file, standard namespace, and closing of main’s function definition.
  • Therefore, the given code is modified as follows,

//Declare the header file

#include <iostream>

//Declare the namespace

using namespace std;

//Define the main function

int main()

{

    //Declare the variable

    int userNum;

    //Assign the value

    userNum = 5;

    //Print the string

    cout << "Foretelling is hard." << endl;

    //Print the string

    cout << "Particularly of the future." << endl;

    //Print the string

    cout << "User num is:" << userNum << endl;

    //Return “0”

    return 0;

}

Step 2

Explanation about the modified code:

  • The header file “<iostream>” is declared.
  • The standard namespace “std” is declared using the keyword “using”, which tells the compiler that the declared name is in the declared namespace.
  • The function “main()” is defined.
  • The variable “userNum&r...
help_outline

Image Transcriptionclose

//Declare the header file #include <iostream> //Declare the namespace using namespace std; //Define the main funcion int main /Declare the variable int userNum //Assign the value userNum =5; //Print the string cout <"Foretelling is hard." « endl; //Print the string cout <"Particularly of the future." < endl //Print the string cout <"User num is:" << userNum « endl //Return "O" return 0;

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Visual Basic. Given two variables, isEmpty of type boolean, indicating whether a class roster is emp...

A: We have to check two conditions:-1) class roster is not empty 2) The class has more than two credits...

question_answer

Q: 2. What are ‘accelerated filers’ and how are they selected- revenue, # employee, etc.

A: If a company meets the following conditions at the fiscal year end, it is considered as accelerated ...

question_answer

Q: Hello, please I need help with the following using Python:   Write flowchart, pseudo-code and progra...

A: Pseudocode:Import module statistics and Declare variables Students and Student_listPrompt for the nu...

question_answer

Q: 4-20) (Process a string) Write a program that prompts the user to enter a string and displays its le...

A: Program to enter the string by the user to display its length and first character.

question_answer

Q: What language is accepted by the Turing machine whose transition graph is in the figure below?

A: Turing machine:Turing machine is a model of a hypothetical computing machine which can use a predefi...

question_answer

Q: Write two scnr.nextInt statements to get the input values into birthMonth and birthYear.Then write a...

A: Given below is the program to get input values for month and year and write the output value as a mo...

question_answer

Q: a. What are the values of i, j, k after the if statement runs?int i = 3, j = 2, k=9;if (i &lt; j)if ...

A: The values of i, j and k for the given program are:3, 2 and 4In the program, if-else condition is th...

question_answer

Q: Problem: Develop a class encapsulating the concept of a college course, assuming that a course has f...

A: The program has the following algorithm: Course.javaCreate default constructors.Test the “set” metho...

question_answer

Q: I was asked to add the three types of comments to this class, each consisting of the same statement ...

A: Java documentation comment: This comment is used to create documentation API. The syntax for this co...