Thread: input/output

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    22

    input/output

    currently wrote a bank account type code it compiles well but instead of givign a starting bank account of 40 when i run it it gives a starting bank account of 22 + the deposit. I also tryed usign a const for the starting bank account so i just did bank == 40. take a look at the code
    think im starting to get the hang of this another week or two practicing code n ill move up

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      int i;
      int bank;
      bank == 40;
      cout<<"You have 40 dollars in your account" << endl;
      cout << "Enter how much money you want to deposit: ";
      cin >> i;
      cin.ignore();
      cout << "You have " << bank + i <<" in your account "<< endl;
      cout << " and an interest rate of " << (bank + i) * .05 <<" per month "<< endl;
      cin.get();
    }

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    heres better example of code maybe thsi will help give u an idea of what im talking about. I declare bank as 40 but keeps sayign its 22. why is this?

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      int i;
      int bank;
      bank == 40;
      cout<<"You have "<< bank << "dollars in your account" << endl;
      cout << "Enter how much money you want to deposit: ";
      cin >> i;
      cin.ignore();
      cout << "You have " << bank + i <<" in your account "<< endl;
      cout << " and an interest rate of " << (bank + i) * .05 <<" per month "<< endl;
      cin.get();
    }

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Kevineze
    I declare bank as 40 but keeps sayign its 22. why is this?
    Code:
      bank == 40;
    This statement has no effect. it just checks if bank is 40 and discards the result of the comparison.
    it should be
    Code:
      bank = 40;
    Kurt

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    how do I make the statement take effect?
    Ok sry didnt notice the == vrs the = there lol I got It its working now thanks.
    Last edited by Kevineze; 11-25-2006 at 06:28 PM.

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Quote Originally Posted by Kevineze
    how do I make the statement take effect?
    What? He just showed you.
    Code:
    bank==40
    Is comparing, not assigning the value of 40. You want to use
    Code:
    bank=40
    If this is going to be constant, use:
    Code:
    const int bank;
    Also, don't post stupid short statements, use the edit button for that.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If this is going to be constant, use:
    Code:
    const int bank;
    Remember to initialize constants . . .
    Code:
    const int bank = 40;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with input/output files
    By aldin176 in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2006, 09:04 AM
  2. Input/Output Streams
    By mikeprogram in forum C++ Programming
    Replies: 6
    Last Post: 12-23-2005, 02:58 PM
  3. input/output
    By JCK in forum C++ Programming
    Replies: 4
    Last Post: 11-30-2002, 12:07 PM
  4. FILE input/output and ARRAY
    By poorman in forum C Programming
    Replies: 1
    Last Post: 03-05-2002, 04:17 PM
  5. Input/Output
    By PaulMelia in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 08:13 AM