I haven't done much in C++ lately.
Visual C++ 2010 is still unmanaged code without Win32 wrappers and completely allows for unsafe code, no?
Visual C++ is just the IDE, not a language, C++/CLI is the replacement for managed C++.
I haven't done much in C++ lately.
Visual C++ 2010 is still unmanaged code without Win32 wrappers and completely allows for unsafe code, no?
System Name | ALIENWARE R8 |
---|---|
Processor | INTEL I5 9500 @3.9Ghz |
Motherboard | ALIENWARE 02XRCM |
Cooling | ALIENWAR Liqid Cooler |
Memory | DDR4 16GB @2.8Ghz |
Video Card(s) | NVIDIA GForce RTX 2070 8GB |
Storage | 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB |
Display(s) | VIZIO E-241 25" TV |
Case | ALIENWARE R8 |
Power Supply | 850 WATTS |
Mouse | ROSWILL NEON M60 |
Keyboard | ALIENWARE |
Software | WIN 10 |
Here it is, would probably be easier to read to just c-n-p it to a doc or something: Edit: Fixed the division by zero issue (i think), just had to add two if statements.
case WM_LBUTTONDOWN:{
XCoord=(int)LOWORD(lparam);
YCoord=(int)HIWORD(lparam);
if (StartFlag==true){
for (int i=0;i<=MaxDie-1;i++){
if (DiceRolls[i]>=0){
if (Die_Selected[i]==false){
if (XCoord >=DiceShell[i].left && XCoord <=DiceShell[i].right){
if (YCoord >=DiceShell[i].top && YCoord <=DiceShell[i].bottom){
FillRect(g_Hdc,&DiceShell[i],RedBrush);
FrameRect(g_Hdc,&DiceShell[i],OutLineBrush);
Die_Selected[i]=true;
PrintNumbers();
}
}
}else{
if (XCoord >=DiceShell[i].left && XCoord <=DiceShell[i].right){
if (YCoord >=DiceShell[i].top && YCoord <=DiceShell[i].bottom){
FillRect(g_Hdc,&DiceShell[i],WhiteBrush);
FrameRect(g_Hdc,&DiceShell[i],OutLineBrush);
Die_Selected[i]=false;
PrintNumbers();
}
}
}
}
}
}
return(0);
break;
}
System Name | Freyja |
---|---|
Processor | Core i7 3770K |
Motherboard | AsRock Z77 Extreme4 |
Cooling | Cooler Master Hyper 212 EVO |
Memory | 16 GB GSkill Sniper |
Video Card(s) | Diamond Radeon HD 7970 |
Storage | Kingston HyperX 240 GB SSD + Seagate 2 TB HD |
Display(s) | Dell U2410 |
Case | NZXT Tempest 210 |
Audio Device(s) | Asus Xonar Essence STX |
Power Supply | Seasonic X-Series 750W |
Software | Ubuntu 13.04 64 bit |
System Name | ALIENWARE R8 |
---|---|
Processor | INTEL I5 9500 @3.9Ghz |
Motherboard | ALIENWARE 02XRCM |
Cooling | ALIENWAR Liqid Cooler |
Memory | DDR4 16GB @2.8Ghz |
Video Card(s) | NVIDIA GForce RTX 2070 8GB |
Storage | 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB |
Display(s) | VIZIO E-241 25" TV |
Case | ALIENWARE R8 |
Power Supply | 850 WATTS |
Mouse | ROSWILL NEON M60 |
Keyboard | ALIENWARE |
Software | WIN 10 |
System Name | Freyja |
---|---|
Processor | Core i7 3770K |
Motherboard | AsRock Z77 Extreme4 |
Cooling | Cooler Master Hyper 212 EVO |
Memory | 16 GB GSkill Sniper |
Video Card(s) | Diamond Radeon HD 7970 |
Storage | Kingston HyperX 240 GB SSD + Seagate 2 TB HD |
Display(s) | Dell U2410 |
Case | NZXT Tempest 210 |
Audio Device(s) | Asus Xonar Essence STX |
Power Supply | Seasonic X-Series 750W |
Software | Ubuntu 13.04 64 bit |
Thx for the link.. When I was in school, they told us to the the using namespace std;
You're only hearing that (and the "using std" bit) from veteran programmers who are working on non-trivial programs. For a program of the complexity you wrote it's not exactly going to break the bank with performance/portability; it's just "good practice" and programmers like their "good habits".Yeah I was taught that too, but then they also taught us to use system("pause"), which is a huge no-no.
System Name | Freyja |
---|---|
Processor | Core i7 3770K |
Motherboard | AsRock Z77 Extreme4 |
Cooling | Cooler Master Hyper 212 EVO |
Memory | 16 GB GSkill Sniper |
Video Card(s) | Diamond Radeon HD 7970 |
Storage | Kingston HyperX 240 GB SSD + Seagate 2 TB HD |
Display(s) | Dell U2410 |
Case | NZXT Tempest 210 |
Audio Device(s) | Asus Xonar Essence STX |
Power Supply | Seasonic X-Series 750W |
Software | Ubuntu 13.04 64 bit |
You're only hearing that (and the "using std" bit) from veteran programmers who are working on non-trivial programs. For a program of the complexity you wrote it's not exactly going to break the bank with performance/portability; it's just "good practice" and programmers like their "good habits".
I still use "printf()" for debugging, and I know I shouldn't.
I didn't post earlier because I don't want to be a dick but you know there are quite a few (free) math libraries for C/C++ that implement those functions. I still think you wrote a solid program and I like your commenting style.
![]()
System Name | ALIENWARE R8 |
---|---|
Processor | INTEL I5 9500 @3.9Ghz |
Motherboard | ALIENWARE 02XRCM |
Cooling | ALIENWAR Liqid Cooler |
Memory | DDR4 16GB @2.8Ghz |
Video Card(s) | NVIDIA GForce RTX 2070 8GB |
Storage | 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB |
Display(s) | VIZIO E-241 25" TV |
Case | ALIENWARE R8 |
Power Supply | 850 WATTS |
Mouse | ROSWILL NEON M60 |
Keyboard | ALIENWARE |
Software | WIN 10 |
//Neil W. Reich
//4-1-10
//CREDITS:
#include <htc.h>
#include "Sequences.h"
#include "Demo.h"
//*********************************
// CONFIGURATION FLAGS
//DEBUGGER MODE
__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPDIS & WRTEN &
DEBUGEN & DUNPROT & UNPROTECT);
////PROGRAMMER MODE
//__CONFIG(XT & WDTDIS & PWRTDIS & BORDIS & LVPEN & WRTEN &
//DEBUGEN & DUNPROT & UNPROTECT);
//Prototyped functions
void Init();
void ProgramStart();
//Variable Declarations
int Selection;
long Idle;
bit DemoFlag;
//Functions
void Init(){
ADON=0; //Analog turned off
PORTA=0;
PORTB=0;
TRISB= 0b00000001; //Sets port B0 for input
TRISA4=1; //Sets port A for input
Selection=0;
Idle=0;
DemoFlag=0;
}
/////////////////START OF PROGRAM////////////////////////////
void main(){
Init();
ProgramStart();
/////////////////////M E N U /////////////////////////
switch(Selection){
case 1:
FancyDance_LEE();
break;
case 2:
StopLight_MC();
break;
case 3:
Chaser_Willie();
break;
case 4:
SpeedTrap_LEE();
break;
case 5:
thingamajig_Jensen();
break;
case 6:
DOGBIRT();
break;
case 7:
DEMO();
break;
default:
DEMO();
break;
}
}
void ProgramStart(){
do{
Idle++; //counts inactivity
if(is_button_RA4_pressed()==1){//listens for button activity. a return value of 1 is yes,0 is no
Idle=0; //resets because of Activity
Selection++; //counts the times the butten is pressed
PORTB=Selection<<1; //Displays the count in binary
if (Selection>7){ //resets the counter when 7 is reached
Selection=1;
PORTB=Selection<<1;
}
}
Delay(3);
if (Idle > LIMIT-1){ //Starts demo if true
Idle=0;
DEMO();
Init();
}
}while(is_button_RB0_pressed() ==0); //Exits loop when RB0 is pressed
}
//DELAY FOR LED'S AND BUTTONS
void Delay( int duration){
unsigned int i;
for(;duration!=0;duration--){
for(i=0;i<=TIME;i++){
NOP();
NOP();
NOP();
}
NOP();
NOP();
}
}
///////////////////DEBOUNCED BUTTONS//////////////////////////
unsigned char is_button_RA4_pressed(void){
if (RA4==0) { // is button pressed?
Delay(60); // wait
if (RA4==0) { // is button still has pressed status after delay?
return 1; // if key pressed,return 1
}
}
return 0; // if key is not pressed, return 0
}
unsigned char is_button_RB0_pressed(void){
if (RB0==0) { // is button pressed?
Delay(60); // wait
if (RB0==0) { // is button still has pressed status after delay?
return 1; // if key pressed,return 1
}
}
return 0; // if key is not pressed, return 0
}
//CALIBRATION DATA
#define TIME 100 //for calibrating the delay.. # of NOP's X3
#define LIMIT 2000 //Maximum inactivity( interations of while) allowed
#define MAXDEMO 1 //Maximum time demo will repeat
//Used for Dogbirt function only
#define BASEDELAY 10 //Default Delay Time
#define MAXTIMES 10 //Maximum interations in one direction
#define PLACER 50 //Multiplier for delay
//Neil W. Reich
//4-0-10
#include <htc.h>
#include "Global.h"
//Header file that contains all of the various light sequences
//DEFINES LEDS
#define RED 0x02
#define YELLOW 0x04
#define GREEN 0x08
#define CLEAR 0x00
//***************LIGHT SEQUENCES**************
void SpeedTrap_LEE(){
while (is_button_RB0_pressed() ==0){
PORTB = GREEN;
Delay(700);
PORTB =YELLOW;
Delay(150);
PORTB = RED;
Delay(700);
}
}
void FancyDance_LEE(){
while (is_button_RB0_pressed()==0){
PORTB = GREEN+RED;
Delay(400);
PORTB = YELLOW;
Delay(100);
PORTB =GREEN+RED;
Delay(400);
}
}
void StopLight_MC(){
while (is_button_RB0_pressed()==0){
PORTB = RED;
Delay(400);
PORTB = YELLOW;
Delay(400);
PORTB =RED;
Delay(400);
PORTB = GREEN;
Delay(400);
PORTB = YELLOW;
Delay(400);
PORTB =GREEN;
Delay(400);
}
}
void Chaser_Willie(){
while (is_button_RB0_pressed()==0){
PORTB = RED;
Delay(253);
PORTB =YELLOW;
Delay(253);
PORTB = GREEN;
Delay(253);
PORTB = YELLOW;
Delay(253);
}
}
void thingamajig_Jensen(){
while (is_button_RB0_pressed()==0){
PORTB =YELLOW+GREEN;
// RB3=CLEAR;
Delay(400);
PORTB = GREEN+RED;//
Delay(300);
PORTB = GREEN+YELLOW;
Delay(300);
PORTB = GREEN+RED;//
Delay(300);
}
}
void DOGBIRT(){
int Count=0;
int Count1=0;
while(1){
Count++;
if (Count<MAXTIMES){
// BaseDelay=(BaseDelay+PLACER);
for(int j=1;j<=4;j++){
PORTB=1<<j; //interation j1=2;j2=4;j3=8\
Delay(BaseDelay);
// MaxLimit=BASEDELAY+(PLACER*Count);
}
}else{
for(int j=0;j<=3;j++){
PORTB=8>>j; //interation j0=2;j1=4;j2=8
//Delay((PLACER*Count)-MaxLimit);
}
}
if (Count>=MAXTIMES*2){
Count=0;
}
}//end while
}
System Name | Freyja |
---|---|
Processor | Core i7 3770K |
Motherboard | AsRock Z77 Extreme4 |
Cooling | Cooler Master Hyper 212 EVO |
Memory | 16 GB GSkill Sniper |
Video Card(s) | Diamond Radeon HD 7970 |
Storage | Kingston HyperX 240 GB SSD + Seagate 2 TB HD |
Display(s) | Dell U2410 |
Case | NZXT Tempest 210 |
Audio Device(s) | Asus Xonar Essence STX |
Power Supply | Seasonic X-Series 750W |
Software | Ubuntu 13.04 64 bit |
System Name | ALIENWARE R8 |
---|---|
Processor | INTEL I5 9500 @3.9Ghz |
Motherboard | ALIENWARE 02XRCM |
Cooling | ALIENWAR Liqid Cooler |
Memory | DDR4 16GB @2.8Ghz |
Video Card(s) | NVIDIA GForce RTX 2070 8GB |
Storage | 512 MB M.2, KINGSTON 480 GB SSD,SEAGATE 3 TB |
Display(s) | VIZIO E-241 25" TV |
Case | ALIENWARE R8 |
Power Supply | 850 WATTS |
Mouse | ROSWILL NEON M60 |
Keyboard | ALIENWARE |
Software | WIN 10 |
System Name | Freyja |
---|---|
Processor | Core i7 3770K |
Motherboard | AsRock Z77 Extreme4 |
Cooling | Cooler Master Hyper 212 EVO |
Memory | 16 GB GSkill Sniper |
Video Card(s) | Diamond Radeon HD 7970 |
Storage | Kingston HyperX 240 GB SSD + Seagate 2 TB HD |
Display(s) | Dell U2410 |
Case | NZXT Tempest 210 |
Audio Device(s) | Asus Xonar Essence STX |
Power Supply | Seasonic X-Series 750W |
Software | Ubuntu 13.04 64 bit |