Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-22-2004, 11:21 PM   #1 (permalink)
fuzzybunny3
Registered User
 
fuzzybunny3's Avatar
 
Join Date: Oct 2004
Posts: 4
fuzzybunny3 is on a distinguished road
HELP console exits once i start program

:rock: I'm new! I mean new! Like just started today and I have a problem I try this code:

34fx// Lost Fortune
// A personalized adventure

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
const int GOLD_PIECES = 900;
int adventurers, killed, survivors;
string leader;

//get the information
cout << "Welcome to Lost Fortune\n\n";
cout << "Please enter the following for your personalized adventure\n";

cout << "Enter a number: ";
cin >> adventurers;

cout << "Enter a number, smaller than the first: ";
cin >> killed;

survivors = adventurers - killed;

cout << "Enter your last name: ";
cin >> leader;

//tell the story
cout << "\nA brave group of " << adventurers << " set out on a quest ";
cout << "-- in search of the lost treasure of the Ancient Dwarves. ";
cout << "The group was led by that legendary rogue, " << leader << ".\n";

cout << "\nAlong the way, a band of marauding ogres ambushed the party. ";
cout << "All fought bravely under the command of " << leader;
cout << ", and the ogres were defeated, but at a cost. ";
cout << "Of the adventurers, " << killed << " were vanquished, ";
cout << "leaving just " << survivors << " in the group.\n";

cout << "\nThe party was about to give up all hope. ";
cout << "But while laying the deceased to rest, ";
cout << "they stumbled upon the buried fortune. ";
cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
cout << leader << " held on to the extra " << (GOLD_PIECES % survivors);
cout << " pieces to keep things fair of course.\n";

return 0;
}




It first works I enter the first two values it ask me and then I put in the third i enter it in and press enter it exits the whole program. I think I need something to pause the whole program to see the rest. What could that be???
fuzzybunny3 is offline   Reply With Quote
Old 10-23-2004, 10:54 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
You will need to build your own functions. Copy and paste this to a file to back it up.
Code:
#include <string>
#include <climits>

using namespace std;

void reset_istream( )
{
   //Reset failstate just in case.
  cin.clear();
   cin.ignore(numeric_limits<streamsize>::max(), '\n');
}

//---------------------------------------------------

void wait_for_enter()
{
  cout << "press <enter> to continue...\n";
  // Reset failstate, just in case.
  cin.clear();
  string line;
  getline( cin, line);
}
You can see in this thread:
Reversing a string and palindromes.
how to use it.
__________________

Last edited by Valmont; 10-23-2004 at 12:16 PM.
Valmont is offline   Reply With Quote
Old 10-23-2004, 05:52 PM   #3 (permalink)
fuzzybunny3
Registered User
 
fuzzybunny3's Avatar
 
Join Date: Oct 2004
Posts: 4
fuzzybunny3 is on a distinguished road
thanks!!!

tHANK YOU I NEEDED THAT
fuzzybunny3 is offline   Reply With Quote
Old 10-24-2004, 08:10 PM   #4 (permalink)
Kernel_Killer
Regular Contributor
 
Kernel_Killer's Avatar
 
Join Date: Feb 2003
Location: indisclosed
Posts: 210
Kernel_Killer is on a distinguished road
I'm a while whore when it comes to such things. I like to test multiple results, and keep the application going. Like so:


Code:
// Lost Fortune
// A personalized adventure

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
        const int GOLD_PIECES = 900;
        int adventurers, killed, survivors;
        string leader;

        //get the information
        cout << "Welcome to Lost Fortune\n\n";
        cout << "Please enter the following for your personalized adventure\n";

        cout << "Enter a number: ";
        cin >> adventurers;

        while(adventurers != 0)
        {
                cout << "Enter a number, smaller than the first: ";
                cin >> killed;
                survivors = adventurers - killed;

                cout << "Enter your last name: ";
                cin >> leader;

                //tell the story
                cout << "\nA brave group of " << adventurers << " set out on a quest ";
                cout << "-- in search of the lost treasure of the Ancient Dwarves. ";
                cout << "The group was led by that legendary rogue, " << leader << ".\n";

                cout << "\nAlong the way, a band of marauding ogres ambushed the party. ";
                cout << "All fought bravely under the command of " << leader;
                cout << ", and the ogres were defeated, but at a cost. ";
                cout << "Of the adventurers, " << killed << " were vanquished, ";
                cout << "leaving just " << survivors << " in the group.\n";

                cout << "\nThe party was about to give up all hope. ";
                cout << "But while laying the deceased to rest, ";
                cout << "they stumbled upon the buried fortune. ";
                cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
                cout << leader << " held on to the extra " << (GOLD_PIECES % survivors);
                cout << " pieces to keep things fair of course.\n";
        }
        return 0;
}
Kernel_Killer is offline   Reply With Quote
Reply

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM
Need help on program B00tleg Standard C, C++ 1 10-12-2004 12:02 AM


All times are GMT -8. The time now is 04:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting