NathanMullenax's Profile User Rating: *****

Reputation: 86 Whiz
Group:
Contributors
Active Posts:
189 (0.23 per day)
Joined:
23-September 12
Profile Views:
5,198
Last Active:
User is offline Dec 02 2014 09:12 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Linux
Favorite Browser:
Chrome
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Classic
Your Car:
Who Cares
Dream Kudos:
25

Latest Visitors

Icon   NathanMullenax Former programmer, current 'kitchen dude'.

Posts I've Made

  1. In Topic: I need some help! How to make multi cout/cin in the same line?

    Posted 20 Nov 2014

    Jim is right, but you could read the strings character by character using getch, only printing if the character is not a return ('\n'). This is assuming the getch() function doesn't echo characters to the screen. If you do that, you'll have to handle also what happens when the user hits backspace an arrow key or anything else you don't want to be read as input for your strings.
  2. In Topic: Reading from files using the operator ">>"

    Posted 20 Nov 2014

    Here's one way you might end up in an infinite loop with a failed stream:
    #include <iostream>
    
    using std::cin;
    using std::cout;
    
    void
    print_rdstate( std::istream &s )
    {
      if( s.good() )
        {
          cout << "The stream is good.\n";
        }
      else 
        {
          if( s.eof() )
    	cout << "End of file: There is nothing left to read.\n";
          if( s.bad() )
    	cout << "Tried to read something that wasn't there.\n";
        }
    }
    
    int
    main()
    {
      int c;
      // loop runs until extraction fails
      while( cin >> c )
        print_rdstate(cin);
    
      cout << "Left while loop...\n";
      print_rdstate(cin); 
      
      // this loop will run forever without accepting any further input
      bool running(true);
      while(running)
        {
          cout << "Give me an integer of give me death.\n";
          cin >> c;    // at this point stream is failed, so extraction silently fails
          if( c==42 )
    	break;
        }
    }
    
  3. In Topic: trying to avoid global variable

    Posted 6 Nov 2014

    Or, something like this:
    #include <iostream>
    
    static class {
    private:
      int table[201];  
    public:
      void init()
      {
        for(int i=0; i<201; ++i)
          table[i] = i%2==0?i/2:3*i+1;
      }
      double operator() (double x )
      {
        return table[ static_cast<unsigned>(x) ];
      }
    } fun;
    
    int main()
    {
      fun.init();
      std::cout << fun( 3.4 ) << "\n";
    }
    
  4. In Topic: trying to avoid global variable

    Posted 6 Nov 2014

    In C++11, something like this would work:

    #include <iostream>
    #include <functional>
    
    std::function< double(double) > fun;
    
    int main()
    {
      int vs[] = {1,2,3,4,5,6,67,78};
      // functor captures vs
      fun = [vs] ( double x ) {
        return vs[ static_cast<int>( x ) ];
      };
    
      std::cout << fun(4.0) << "\n"; 
    }
    
  5. In Topic: Find maximal points among given 'n' points

    Posted 4 Nov 2014

    View Postinfernorthor, on 03 November 2014 - 09:45 PM, said:

    Finding max x then max y would take 2N


    I meant 'consider' intellectually. I'm not suggesting you loop through the points twice.

My Information

Member Title:
D.I.C Head
Age:
30 years old
Birthday:
December 29, 1983
Gender:
Location:
Fort Myers, Florida
Full Name:
Nathan Mullenax
Programming Languages:
C++, Java, SML/NJ, QBasic, Haskell, C#, ColdFusion, SQL, PHP, Python, INTERCAL

Contact Information

E-mail:
Click here to e-mail me
LinkedIn:
http://www.linkedin.com/pub/nathan-mullenax/57/3ab/a27
Facebook:
http://facebook.com/jelehfish

Friends

Comments

Page 1 of 1
  1. Photo

    rbk3ai Icon

    02 Oct 2012 - 16:00
    Thanks man you got mad skills!
Page 1 of 1