Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 7th, 2004, 4:00 PM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Dec 8th, 2004, 1:18 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Dec 8th, 2004, 8:51 PM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Dec 9th, 2004, 3:50 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Eggy says that's bad, and he's the don, so there
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Dec 11th, 2004, 4:16 AM   #5
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Dec 11th, 2004, 9:56 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC