Welcome Guest [Log In] [Register]
Add Reply
How do I get this to not close automatically; have this code that i can't use cin.get
Topic Started: Apr 8 2009, 09:19 AM (359 Views)
Darksorrow131

Note the two lines I added (labeled with /******/). You can change it slightly to ask the user whether to continue by adding a break statement somewhere.
Code:
 

#include <iostream>

int oz(int);
int main()
{
using namespace std;
/******/ while(true) { /******/
cout<<"hello! how many pounds do you weigh: ";
int lbs;
cin >> lbs;
int ounces;
ounces = oz(lbs);
cout << "You weigh " << lbs <<" which is " << ounces << " ounces" << endl;
/******/ } /******/
system("PAUSE");
}

int oz(int oz2lbs)
{
return 16 * oz2lbs;
}
(let loop () (loop))
((lambda (x) (x x)) (lambda (x) (x x)))
(let ((k #f)) (call/cc (lambda (cc) (set! k cc)) (k))
((call/cc call/cc) (call/cc call/cc))

-- Infinite loops are awesome! --
Tell me if you have other awesome infinite loops!
Offline Profile Quote Post Goto Top
 
Cosmic_AC

Actually, your function does lbs2oz.
++++++++++[>+++++++>+++++++++++<<-]>---.>+.++++.------.----.------.<<++++[>>+++++++<<-]>>.<---.+++.
Offline Profile Quote Post Goto Top
 
SheWasAlmost18
Member Avatar

thx

cna you explain waht /******/ is?
We are made kind by being kind
Offline Profile Quote Post Goto Top
 
Darksorrow131

It's nothing, just something I added to make it obvious which line I added.
(let loop () (loop))
((lambda (x) (x x)) (lambda (x) (x x)))
(let ((k #f)) (call/cc (lambda (cc) (set! k cc)) (k))
((call/cc call/cc) (call/cc call/cc))

-- Infinite loops are awesome! --
Tell me if you have other awesome infinite loops!
Offline Profile Quote Post Goto Top
 
SheWasAlmost18
Member Avatar

ohhh ok
We are made kind by being kind
Offline Profile Quote Post Goto Top
 
MMZJSFMMX10MM
Member Avatar

/*
*/

is a block comment. When he put it like /*****/ it just thought it was a block comment. A block comment is similar to a // comment. Except everything after // is ignore when the program runs. Everything inside /* I am ignored */ gets ignored.
Posted Image
Posted Image
Posted Image
Offline Profile Quote Post Goto Top
 
Cosmic_AC

/* */ is used to specify a comment that is bigger or smaller than exactly one line.

We really need some sort of indentation and/or bbcode syntax that works inside a [code] tag.
++++++++++[>+++++++>+++++++++++<<-]>---.>+.++++.------.----.------.<<++++[>>+++++++<<-]>>.<---.+++.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Application Programming Support · Next Topic »
Add Reply

Banner and Logo by TheKeith