?
Solved

Easy C++ commands

Posted on 2000-02-28
3
Medium Priority
?
194 Views
Last Modified: 2010-04-02
I am trying to learn C++,and I haven't bought any books or anything yet so I have a few questions.
I think I've understood that with int var = value -- you set a variabel value, but how do i set it to something a user is prompted for?
so that i ask the user what the value should be.
0
Comment
Question by:thejackal
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Michael_OReilly earned 80 total points
ID: 2566993
Countless ways to do this ... handiest (and VERY common way of doing it (coming from C history, and by now a programing idiom) probably being the following which also works fine in c++:

#include <stdio.h>
int x;
printf("Enter a number: ");
scanf("%d", &x);

or if u want a more standard c++ parlance:

int x;
cout << "Enter a number: ";
cin >> x;
cout << "You entered " << x << endl; // the endl means skip a line
0
 

Author Comment

by:thejackal
ID: 2574707
Thanks alot! :)
0
 
LVL 1

Expert Comment

by:Michael_OReilly
ID: 2575722
you're welcome
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question