Newbie question or dumb?idk

This is a discussion on Newbie question or dumb?idk within the C++ Programming forums, part of the General Programming Boards category; Yea, im wonderin if i could make, a very simple program i made in a very short period of time,-(i ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    8

    Newbie question or dumb?idk

    Yea, im wonderin if i could make, a very simple program i made in a very short period of time,-(i was bored lol)- into a stand alone non terminating program. I am new to this code and don't know whether it is posible or the slightest idea how to do it.
    The code is...


    Code:
    //Sales tax calculator (CA, Alameda county sales tax)
    
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      int i;
      cout << "Please enter the price: ";
      cin >> i;
      cout << " The price you entered is " << i;
      cout << " The sales tax for this amount is " << 8.75/100*i << ".\n";
      cout << " The total amount is $ " << 8.75/100*i+i ; 
    }


    if you could please explain how to do it that would be great .
    Any edits you think would improve the program or enable me to do what i want, if you could post it that would be appreciated
    Last edited by Prsharp; 07-07-2006 at 10:33 PM.

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    int's can only hold whole (integral(sp?)) numbers. You want a float or a double. Also making the computer do calcs like 8.75/100 is just cpu cycles wasted. Just use 0.0875 .

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    8
    Oh, oops i gave the wrong code i had 0.0875 on my new one i didn't notice i put that one
    thank you for pointing that out. But do know how i can make the program without running it on the Visual Studio 2005 Command Prompt, how do i make it so that if i press enter it wont close while opening it without the Command prompt.

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    8
    Thank you very much Wraithan, i got it to work .
    Just one more question what do i have to do to make it so it will loop
    by that i mean once it has calculated everything and its done what do it do so it reopens without reexecing the exe file?

    ohh one more thing how do i make it say the title of the program on the very top instead of the file directory?
    Last edited by Prsharp; 07-07-2006 at 11:38 PM.

  6. #6
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Question 1: Read the tutorials.

    Question 2: Search the forums, this was answered recently.

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    8
    ok thx man

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> what do i have to do to make it so it will loop

    Use a loop. A while loop would probably be most appropriate.

  9. #9
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Question 1:
    Quote Originally Posted by Prsharp
    Just one more question what do i have to do to make it so it will loop
    by that i mean once it has calculated everything and its done what do it do so it reopens without reexecing the exe file?
    Question 2:
    Quote Originally Posted by Prsharp
    ohh one more thing how do i make it say the title of the program on the very top instead of the file directory?
    Start using google and or searching the forums and you will find most of your questions answered.

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    > how do i make it say the title of the program on the very top instead of the file directory?
    You mean the title bar on the console? In windows, you would have to create a Win32 Console Application and then use an API function SetConsoleTitle to change the title. Well, not the ONLY way, it's the fastest way anyway.

    Code:
    #include <windows.h>
    #include <iostream>
    
    int main()
    {
        SetConsoleTitle("VIP quality window!");
        std::cout << "It's VIP QUALITY!\n";
        return 0;
    }
    It cannot be done in a standard way, because that behavior is completely platform dependant.
    Last edited by whiteflags; 07-08-2006 at 01:15 AM.

  11. #11
    Registered User
    Join Date
    Jul 2006
    Posts
    8
    ok i got it

  12. #12
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> 8.75/100*i

    That won't give you what you want, I think. It'll multiply i by 100, then divide 8.75 by that. I think what you want is i*8.75/100, or to make it clearer, (i*8.75)/100. It figures out brackets first, then the multiplication sign, then the division one, then if you want to use them, addition and subtraction, in that order.

  13. #13
    Registered User
    Join Date
    May 2006
    Posts
    8
    Quote Originally Posted by Wraithan
    Also making the computer do calcs like 8.75/100 is just cpu cycles wasted. Just use 0.0875 .
    Any compiler worth using is going to do such a calculation at compile time, and the only wasted CPU cycles will be during said compilation, not during the program execution.

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    Quote Originally Posted by twomers
    >> 8.75/100*i

    That won't give you what you want, I think. It'll multiply i by 100, then divide 8.75 by that. I think what you want is i*8.75/100, or to make it clearer, (i*8.75)/100. It figures out brackets first, then the multiplication sign, then the division one, then if you want to use them, addition and subtraction, in that order.
    No, that will work fine. Multiplication and division are of the same precidence, read left to right.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  15. #15
    Registered User
    Join Date
    Jul 2006
    Posts
    8
    Yea, i know it was working fine like I had it. I am still trying to change the Title bar name

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  3. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 05:45 PM
  4. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 03:38 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM

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