4 easy question

This is a discussion on 4 easy question within the C++ Programming forums, part of the General Programming Boards category; 1# I am using a double. When I cout out my data I want there to be two digits after ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    20

    4 easy question

    1# I am using a double. When I cout out my data I want there to be two digits after the period. How do I do this? Example 2+3 = 5.00 instead of 5.

    2# When I use tabs (the ones on your keyboards) it works like regular tabs (as it would in MS word, or notepad). When you hit tab it moves the cursor to a certain location and everything you type is added and it expends to the right. How do I make it to expand to the left? (for example, tell ms word to align everything to the right, when you add text, its pushed to the left to make room.) I need this info simple to make my program look better.

    3# What is the best and easy way to erase the whole screen (so I can output the data to a clean screen).

    4# I am trying to calculate balance in a savings account... But the problem is the formulate is
    AmountInSavings = Principle * ((1 + (InterestRate/TimesCompounded)) ^ TimesCompounded)

    The problem there is the fact that you can not scare root double numbers (and InterestedRate is a fraction).

  2. #2
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    To your first question look up 'setprecision'.
    Use 'std::fill' for your second.
    Look in the FAQ
    I didn't know doubles could be scared!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    1)

    Code:
    #include <iomanip>
    ...
    ...
    cout<<fixed<<setprecison(2)<<your_var;
    2) and 3) See here:

    http://www.adrianxw.dk/SoftwareSite/...Consoles1.html

    If you want to keep 3) simple, you can do this:
    Code:
    for(int i=0; i<100; i++) 
        cout<<endl;
    4) Huh?

    double pow( double base, double exp );
    Last edited by 7stud; 10-15-2005 at 11:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. easy Vector contructor question
    By noodle24 in forum C++ Programming
    Replies: 5
    Last Post: 04-21-2006, 08:43 PM
  2. Another Embarassingly Easy Question
    By almo89 in forum C Programming
    Replies: 2
    Last Post: 02-11-2006, 04:59 PM
  3. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 01:36 AM
  4. Quick Easy Question
    By St0rmTroop3er in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-24-2004, 01:08 AM
  5. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 01:19 PM

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