Repeating part of a code with changes

This is a discussion on Repeating part of a code with changes within the C++ Programming forums, part of the General Programming Boards category; I mean for a calculator. Code: cout<<"Enter number"<<endl; cin>>a; cout<<"Enter operator"<<endl; cin>>operatorA; cout<<"Enter number"<<endl; cin>>b; cout<<"Finish equation? (Y/N)"<<endl; cin>>YN; And ...

  1. #1
    Registered User bradszy's Avatar
    Join Date
    Jan 2008
    Posts
    114

    Repeating part of a code with changes

    I mean for a calculator.
    Code:
    cout<<"Enter number"<<endl;
    cin>>a;
    cout<<"Enter operator"<<endl;
    cin>>operatorA;
    cout<<"Enter number"<<endl;
    cin>>b;
    cout<<"Finish equation? (Y/N)"<<endl;
    cin>>YN;
    And if they type Y, it gives the calculation, and if they type N it loops, but instead of having
    Code:
    cin>>a;
    It would have
    Code:
    cin>>c;
    and same for the operator. Is it possible?
    Last edited by bradszy; 02-23-2008 at 10:15 PM.

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    yes, it's possible but I think you'd rather just use an array(s) (or a vector if you think C++ > C)
    Don't quote me on that... ...seriously

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Skipping part of the code.
    By And3rs in forum C Programming
    Replies: 38
    Last Post: 10-01-2008, 02:52 PM
  2. Code writing issues Part 2...
    By jaybo684 in forum C++ Programming
    Replies: 10
    Last Post: 08-01-2005, 09:28 AM
  3. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 02:37 PM
  4. Replies: 4
    Last Post: 01-16-2002, 12:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21