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.
Delay the closing
Page 1 of 18 Replies - 508 Views - Last Post: 13 June 2008 - 03:08 PM
Replies To: Delay the closing
#2
Re: Delay the closing
Posted 13 June 2008 - 12:53 PM
#3
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.
#4
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
If you have any more problems, just post up your code and I'll show you
#5
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;
}
#6
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
#7
Re: Delay the closing
Posted 13 June 2008 - 02:51 PM
It is because i am using pow()
#8
Re: Delay the closing
Posted 13 June 2008 - 02:55 PM
Oh yeah, didn't see that... sorry
#9
Re: Delay the closing
Posted 13 June 2008 - 03:08 PM
Its ok thanks for the help. It works now.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|