c++ coding easy help

  • caller
  • Born
  • Born
  • caller
  • Posts: 1

Post 3+ Months Ago

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.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6254
  • Loc: Seattle, WA

Post 3+ Months Ago

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. }

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 55 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.