![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
I think I have figured out how to do it, it complies with me and I think its right but the output comes out and immediately goes away (Dos screen), can anyone help?
I somehow tried to play with output cout << i; but I couldn’t figure it out. Thanks.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
float sum =1;
int i=2;
while (sum < 5.0)
{
sum = sum + 1/(float)(i);
i++;
}
cout << i;
}
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
If you're using Windows, you can use the getch() function to return the first character press, essentially waiting for the user to press any key:
cout << "Press any key to continue..."; getch(); return 0; You should return an integer if you're going to define main as an int - most people return 0. Put that just before the closing brace. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
Alternatively, you could also include stdlib.h and use
system("PAUSE"); If you don't plan on porting to other operating systems and such.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Eggy says that's bad, and he's the don, so there
![]() |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Thanks guys.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
float sum =1;
int i=2;
while (sum < 5.0)
{
sum = sum + 1/(float)(i);
i++;
}
cout << i <<endl;
system("PAUSE");
return 0;
}
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
The "Don" ... lol
You're welcome TechBrain
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|