Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 05-28-08   #1 (permalink)
Folding Fanatic
 
smoke12291's Avatar
 
intel nvidia

Join Date: Apr 2008
Location: California, USA
Posts: 1,026
Blog Entries: 1

Rep: 55 smoke12291 is acknowledged by some
Unique Rep: 49
Folding Team Rank: 286
Trader Rating: 0
Default C++, quiting during runtime

hey guys.

in class right now and writing a basic C++ program.
what is the syntax to quit using the letter "q" or "Q" using a while loop?

thanks
__________________
fold for a purpose, save a life, its a great cause. learn here!
Quote:
Originally Posted by ENTERPRISE View Post
Fold For The Cause ! Fold For The People .

System: The Gamer
CPU
intel q6600 G0 @ 3.0ghz
Motherboard
asus 750i
Memory
2GB corsair xms2 pc-6400
Graphics Card
evga 9800gtx 512mb (774c/1166m/1944s)
Hard Drive
320gb 16mb cache
Power Supply
apevia warlock 750 watt
Case
apevia x-telestar s-type
CPU cooling
Thermaltake DuOrb
GPU cooling
accelero s1 w/two 120mm fans
OS
vista (32-bit)
Monitor
Samsung SyncMaster 932BW 19"
smoke12291 is offline I fold for Overclock.net   Reply With Quote
Old 05-28-08   #2 (permalink)
Programmer
 
intel ati

Join Date: Aug 2006
Location: Moscow, ID
Posts: 154

Rep: 10 Safetydan Unknown
Unique Rep: 9
Trader Rating: 1
Default

I assume you mean that the user should be able to stop the program by pressing the "Q" key. In that case...

read input from the command line:
char input;
cin >> input;

check to see if it's "Q":
if(input == 'Q')

break our of the while loop:
{
break;
}

Or something like that.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which."
Douglas Adams

System: Monster v2
CPU
Q6600 G0
Motherboard
GA-P35-DS3L
Memory
2GB Crucial Ballistix
Graphics Card
Saphire Radeon x1900XTX
Hard Drive
WD 320GB
Sound Card
x-fi extreme music (modded)
Power Supply
OCZ 700W
Case
Gigabyte 3D aurora
CPU cooling
TR Ultra-120 Extreme
GPU cooling
vf900
OS
Windows XP
Monitor
2x Acer 22" WS
Safetydan is offline   Reply With Quote
Old 05-28-08   #3 (permalink)
Folding Fanatic
 
smoke12291's Avatar
 
intel nvidia

Join Date: Apr 2008
Location: California, USA
Posts: 1,026
Blog Entries: 1

Rep: 55 smoke12291 is acknowledged by some
Unique Rep: 49
Folding Team Rank: 286
Trader Rating: 0
Default

i have multiple variables inside a for loop, and im trying to find a way of calling ANY input instead of saying
if ((input == 'q') || (input2 == 'q') || (input3 == 'q')) {
break;
}

but with more variables and with strings
__________________
fold for a purpose, save a life, its a great cause. learn here!
Quote:
Originally Posted by ENTERPRISE View Post
Fold For The Cause ! Fold For The People .

System: The Gamer
CPU
intel q6600 G0 @ 3.0ghz
Motherboard
asus 750i
Memory
2GB corsair xms2 pc-6400
Graphics Card
evga 9800gtx 512mb (774c/1166m/1944s)
Hard Drive
320gb 16mb cache
Power Supply
apevia warlock 750 watt
Case
apevia x-telestar s-type
CPU cooling
Thermaltake DuOrb
GPU cooling
accelero s1 w/two 120mm fans
OS
vista (32-bit)
Monitor
Samsung SyncMaster 932BW 19"
smoke12291 is offline I fold for Overclock.net   Reply With Quote
Old 05-28-08   #4 (permalink)
Folding Fanatic
 
smoke12291's Avatar
 
intel nvidia

Join Date: Apr 2008
Location: California, USA
Posts: 1,026
Blog Entries: 1

Rep: 55 smoke12291 is acknowledged by some
Unique Rep: 49
Folding Team Rank: 286
Trader Rating: 0
Default

nevermind

i could just use a function that will test for the inputs
__________________
fold for a purpose, save a life, its a great cause. learn here!
Quote:
Originally Posted by ENTERPRISE View Post
Fold For The Cause ! Fold For The People .

System: The Gamer
CPU
intel q6600 G0 @ 3.0ghz
Motherboard
asus 750i
Memory
2GB corsair xms2 pc-6400
Graphics Card
evga 9800gtx 512mb (774c/1166m/1944s)
Hard Drive
320gb 16mb cache
Power Supply
apevia warlock 750 watt
Case
apevia x-telestar s-type
CPU cooling
Thermaltake DuOrb
GPU cooling
accelero s1 w/two 120mm fans
OS
vista (32-bit)
Monitor
Samsung SyncMaster 932BW 19"
smoke12291 is offline I fold for Overclock.net   Reply With Quote
Old 05-28-08   #5 (permalink)
New to Overclock.net
 
Join Date: May 2008
Location: Nottingham, UK
Posts: 24

Rep: 7 Stormwolf Unknown
Unique Rep: 5
Trader Rating: 0
Default

In a 'for' loop the stop condition can be as simple or complex as you choose... although simpler is better. What you should be asking is 'why am I using a for loop here?'

A simple rule for using loops in C++ is:

If you have a known or preset number of iterations, use a 'for' loop. You might want to terminate early if you find a match, but you know what the upper bound is.

If you have a task to iterate an unknown number of times, and you might wish to skip the loop entirely, use a 'while' loop (tests on entry into loop)

If you have a task to iterate an unknown number of times, but you wish to execute it at least once, then use a do..while loop.

To answer your original question, you can use the old C functions strchr() or strcmp() defined in string.h. To reduce the number of tests, use the tolower() function to turn upper case into lower case prior to testing.

If you have access to a string class like the MFC CStringT you could do something pretty awful like concatenate all the inputs into a single string and then use the CString.Find() method to search for the occurence of a Q Check out MSDN to see how it works

Last edited by Stormwolf : 05-28-08 at 03:55 PM.
Stormwolf is offline   Reply With Quote
Old 05-28-08   #6 (permalink)
Overclocker
 
Manyak's Avatar
 
intel nvidia

Join Date: Mar 2008
Posts: 2,155

Rep: 186 Manyak is acknowledged by manyManyak is acknowledged by many
Unique Rep: 134
Trader Rating: 12
Default

you can concatenate the input strings together and seek for the bytes you want.
__________________
Under Construction: [Project] Wraith
On Hold: [Project] Belial

System: Gravehouse
CPU
Intel E8400
Motherboard
Intel DX38BT
Memory
OCZ Platinum DDR3-1333
Graphics Card
Geforce 8800gts G80
Hard Drive
2x WD RE2 500GB RAID0
Sound Card
X-Fi Platinum
Power Supply
ABZ Tagan 800W
Case
CM Stacker 832
Manyak is offline   Reply With Quote
Old 05-28-08   #7 (permalink)
Programmer
 
Black Magix's Avatar
 
intel ati

Join Date: Mar 2008
Location: Gunter Air Force Base
Posts: 963

Rep: 96 Black Magix is acknowledged by some
Unique Rep: 67
Hardware Reviews: 2
Trader Rating: 2
Default

or if you prefer the if method. If Input != null
__________________

If you can read this, thank a teacher. If you can read this in English, thank a veteran.
Quote:
Originally Posted by FlaKing View Post
Sweet! I can't wait. To be totally honest, it looks like something my dad would do. A computer is a magical box to him. You put electricity into it and porn comes out.

System: Silent Night
CPU
E3110 Wolfdale
Motherboard
ASUS P5K-E/WIFI-AP
Memory
4GB Corsair Dominator 1066
Graphics Card
Sapphire 1GB HD4850
Hard Drive
2x 750GB 2x 500GB 1x 300GB 1x 250GB
Sound Card
Creative X-Fi Fatality (in the market)
Power Supply
OCZ 700W GamerXstream
Case
Silverstone Kublai
CPU cooling
Zalman Copper Heatsync and fan.
GPU cooling
Stock
OS
Windows Vista Ultimate x64 / Ubuntu 7.10 x86_64
Monitor
Acer 24' Widescreen & Viewsonic 20' Widescreen
Black Magix is offline   Reply With Quote
Old 05-28-08   #8 (permalink)
Programmer
 
Licht's Avatar
 
amd ati

Join Date: Mar 2007
Location: Bel Air
Posts: 8,421
Blog Entries: 3

Rep: 241 Licht is acknowledged by manyLicht is acknowledged by manyLicht is acknowledged by many
Unique Rep: 160
Trader Rating: 0
Default

http://msdn.microsoft.com/en-us/libr...c4(VS.80).aspx

Its the same in C++ if i am not mistaken.

System: AMD-AMD-ATI
CPU
AMD Athlon X2 5200+
Motherboard
Gigabyte 790X AM2+
Memory
2x 1Gb Kingston && 2x 1Gb Wintec
Graphics Card
Saphire HD 3870
Hard Drive
[RAID0] [2X] WD 160GB 7,200RPM
Sound Card
X-Fi Extreme Gamer Fatality Professional
Power Supply
OCZ Game-X-Stream 700w
Case
NZXT Black Steel
CPU cooling
Stock Heatskin & Fan
GPU cooling
Stock Saphire 3870 Cooling
OS
Windows Vista Home Premium x64 SP1
Monitor
Samsung SyncMaster 19" Widescreen
Licht is offline Licht's Gallery   Reply With Quote
Reply



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



All times are GMT -4. The time now is 10:28 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.17992 seconds with 9 queries