Solved

Easy C++ commands

Posted on 2000-02-28
3
178 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 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now