Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++

Status
Not open for further replies.

7220

Technical User
Nov 11, 2002
1
PH
Can anyone please help me to build a syntax for a program.
for example Enter a num: 4 Enter another num: 3 The sum is : 7
 
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
//program goes here

return 0; //ends program
}

to output a line, use cout with the &quot;stream insertion&quot; operatror:

cout << &quot;this is the line I am outputting. &quot;;

to get user input, use cin and the &quot;stream extraction&quot; operator:

int yourVariable;

cin >> yourVariable; //loads input into yourVariable

Of note is that cout can output a wide variety of &quot;cascaded&quot; variables one at a time like this:

cout << &quot;This: &quot; << yourVariable << &quot; is your variable.&quot; << endl;
//where endl dumps text onto the screen (unloads buffer)
// and starts on a new line

If &quot;yourVariable&quot; is, say, 4, the above line will output:
This: 4 is your variable.

So anyway, to relate this all to your question, use cout to ask for integers, cin to load them into variables, assign the sum of the numbers to a variable:

variable3 = variable1 + variable2; //there are other, more
//complicated ways to do this.

then use cout to print the result.

Need to know anything else?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top