Results 1 to 8 of 8

Thread: Simple c++ help

  1. #1
    Join Date
    Jan 2006
    Beans
    239

    Question Simple c++ help

    Ok I have a program which takes the values enter in and then subtracts them from my acount balance, but I'm not sure what's going on.

    #include <iostream>
    using namespace std;

    int main ()
    {
    int citi;
    int chase;
    int bofa;
    int wamu;

    cout << "Please enter your citi total: ";
    cin >> citi;
    cout << "Please enter your chase total: ";
    cin >> chase;
    cout << "Please enter your bofa total: ";
    cin >> bofa;
    cout << "Please enter your wamu total: ";
    cin >> wamu;
    cout << "Your total debt is: "(citi + chase + bofa) - wamu";
    return 0;

    What simple thing am I missing here.

  2. #2
    Join Date
    Mar 2006
    Location
    Ann Arbor, MI
    Beans
    249
    Distro
    Ubuntu 6.10 Edgy

    Re: Simple c++ help

    You didn't state what the problem is, but if it's not compiling it's because you don't have a closing brace for main.

  3. #3
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: Simple c++ help

    If it isn't compiling... It could also be this line:

    Code:
    cout << "Your total debt is: "(citi + chase + bofa) - wamu";
    Notice the stray double quote at the end? And the lack of the "<<" operator between ~is: "~ and ~(~
    Last edited by Wybiral; February 7th, 2007 at 08:14 AM.

  4. #4
    Join Date
    Mar 2006
    Location
    Ann Arbor, MI
    Beans
    249
    Distro
    Ubuntu 6.10 Edgy

    Re: Simple c++ help

    Quote Originally Posted by Wybiral View Post
    If it isn't compiling... It could also be this line:

    Code:
    cout << "Your total debt is: "(citi + chase + bofa) - wamu";
    Notice the stray double quote at the end? And the lack of the "<<" operator between ~is: "~ and ~(~
    That isn't the only problem, there should also be another << operator. What you should do is this:
    Code:
    cout << "Your total debt is: " << (citi + chase + bofa) - wamu << endl;

  5. #5
    Join Date
    Mar 2005
    Location
    Malaysia
    Beans
    300
    Distro
    Ubuntu 6.06 Dapper

    Re: Simple c++ help

    Its probably minor, but you might wanna initialize the variables first too

  6. #6
    Join Date
    Feb 2006
    Beans
    238
    Distro
    Ubuntu 6.10 Edgy

    Re: Simple c++ help

    Its probably minor, but you might wanna initialize the variables first too
    He does initialize the variables, as int. I think you probably want them to be double.

  7. #7
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Simple c++ help

    Quote Originally Posted by LotsOfPhil View Post
    He does initialize the variables, as int. I think you probably want them to be double.
    That's a declaration. An initialization is supplying an initial value, e.g.
    int foo = 0.
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

  8. #8
    Join Date
    Jan 2006
    Beans
    239

    Re: Simple c++ help

    I got it to work. This did the trick for me.

    #include <fstream>
    #include <iostream>
    using namespace std;

    int main ()
    {

    float citi;
    float chase;
    float bofa;
    float wamu;
    float sprint;


    ofstream outFile("finances.file");

    cout << "File open, preparing to write..." << endl;

    cout << "Please enter your WAMU total: ";
    cin >> wamu;
    cout << "Please enter your Citi total: ";
    cin >> citi;
    cout << "Please enter your Chase total: ";
    cin >> chase;
    cout << "Please enter your BofA total: ";
    cin >> bofa;
    cout << "Please enter your Sprint total: ";
    cin >> sprint;

    cout << "Your total debt is: " << wamu - (citi + chase + bofa) << endl;

    outFile
    << "Your WAMU Account Balance is $"<< wamu << ". \n"
    << "Your Citi charge is $" << citi << ". \n"
    << "Your Chase charge is $" << chase << ". \n"
    << "Your BofA charge is $" << bofa << ". \n"
    << "Your Sprint charge is $" << sprint << ". \n"
    << "Your total debt balance is $" << wamu - (citi + chase + bofa + sprint) << ". \n";

    cout << "File written to, and now being closed..." << endl;

    outFile.close();

    return 0;
    }



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •