Solved

Easy C++ commands

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

746 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

16 Experts available now in Live!

Get 1:1 Help Now