c++ coding easy help

  • caller
  • Born
  • Born
  • No Avatar
  • Joined: Nov 20, 2008
  • Posts: 1
  • Status: Offline

Post November 20th, 2008, 6:54 am

First i want to declare, yes i am a noob. I have just started programming and now i need to know how you turn an entire char sentence into int in such a way that you can change it in the console window with a number, and then change it back with the same number.
Thanks beforehand.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post November 20th, 2008, 6:54 am

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Joined: Sep 22, 2003
  • Posts: 6130
  • Loc: Seattle, WA
  • Status: Offline

Post November 20th, 2008, 11:00 pm

If I'm understanding your question correctly, you want to be able to input a number via the console, store that number in a variable, and then modify it again through the console?

If so, you'll want to read up on the I/O objects cin and cout, which will let you interact with standard output. The extraction operator in C++ (>>) will allow you to extract data from standard input based on the type of variable you try and store it in.

For example, to extract an integer from standard input, you might do something like this:

Code: [ Select ]
#include <iostream>

using namespace std;

int main() {

    int number = 0;
    cout << "Enter a number: ";
    cin >> number;
    cout << "You entered " << number << endl;

}
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     int number = 0;
  5.     cout << "Enter a number: ";
  6.     cin >> number;
  7.     cout << "You entered " << number << endl;
  8. }
The Beer Monocle. Classy.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 118 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.