8 Replies - 608 Views - Last Post: 13 June 2008 - 03:08 PM Rate Topic: -----

#1 dvon2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 27-November 07

Delay the closing

Post icon  Posted 13 June 2008 - 12:48 PM

I just started to learn C++. I am writing a program that is out of my tutorials book, but as soon as it does the calculations it needs to it shows them for just a second and it is to fast to see. How can i make it to where it stays open till i hit enter or something like that.
Is This A Good Question/Topic? 0
  • +

Replies To: Delay the closing

#2 manzoor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 13
  • View blog
  • Posts: 468
  • Joined: 07-August 07

Re: Delay the closing

Posted 13 June 2008 - 12:53 PM

Holding The Execution Window Open

This should help
Was This Post Helpful? 0
  • +
  • -

#3 dvon2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 27-November 07

Re: Delay the closing

Posted 13 June 2008 - 01:02 PM

If i put std::cin.get() then it closes as soon as i hit enter. It doesnt help cause i need to be able to hit enter to input the information for it to calculate.
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Delay the closing

Posted 13 June 2008 - 01:05 PM

You should only have std::cin.get(); as the last line of your code, before return 0;

If you have any more problems, just post up your code and I'll show you :)
Was This Post Helpful? 0
  • +
  • -

#5 dvon2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 27-November 07

Re: Delay the closing

Posted 13 June 2008 - 01:12 PM

Yea it still closes as soon as i hit enter. Here is the code.
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	const int PAYMENT	= 360;
	const int TERM		= 48;
	float rate			= 0.0;
	float principal		= 0.0;

	//Enter imput items
	cout<<"Enter the annual interest rate:";
	cin>>rate;
	rate = rate / 12;

	//calculate present value (principal)
	principal = PAYMENT * (1 - pow(rate + 1, -TERM))/rate;


	//display output items
	cout<<fixed;
	cout.precision(0);
	cout<<"You can barrow up to 8" <<principal <<endl;

	cin.get();
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#6 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Delay the closing

Posted 13 June 2008 - 01:17 PM

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    const int PAYMENT    = 360;
    const int TERM        = 48;
    float rate            = 0.0;
    float principal        = 0.0;

    //Enter imput items
    cout<<"Enter the annual interest rate:";
    cin>>rate;
    rate = rate / 12;

    //calculate present value (principal)
    principal = PAYMENT * (1 - pow(rate + 1, -TERM))/rate;


    //display output items
    cout<<fixed;
    cout.precision(0);
    cout<<"You can barrow up to 8" <<principal <<endl;

    cin.ignore();
    cin.get();
    return 0;
}

cin.ignore(); will ignore anything that might be stored in the buffer... it's because you used cin >>
It's nothing too much for you to worry about now, but just bear it in mind for when you get to the more advanced stuff ;)

Hope this helps :)

EDIT: (Been trying to edit for ages, damn connection -_-)
Why do you include cmath? You're not using anything from it. Basic mathematic operations (+, -, /, *, %) are performed as standard... you only need to include cmath when you use something like fmod(), pow(), sqrt(), etc :)

This post has been edited by gabehabe: 13 June 2008 - 01:47 PM

Was This Post Helpful? 0
  • +
  • -

#7 dvon2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 27-November 07

Re: Delay the closing

Posted 13 June 2008 - 02:51 PM

It is because i am using pow()
Was This Post Helpful? 0
  • +
  • -

#8 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Delay the closing

Posted 13 June 2008 - 02:55 PM

Oh yeah, didn't see that... sorry :unsure:
Was This Post Helpful? 0
  • +
  • -

#9 dvon2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 27-November 07

Re: Delay the closing

Posted 13 June 2008 - 03:08 PM

Its ok thanks for the help. It works now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1