Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include<stdio.h> #include<ctype.h> # include <conio.h> # define CLS system("cls") void initialize(void); void screen(void); void input(void); void OpenScreen(void); int get_opt(int,int,char *,int,int); int inv_opt(char *,int,int); int get_cur(int,int,char *); int inv_cur(char *); int hilimit(int); int lolimit(int); int radon(void); int radoff(void); int sprnkon(char); int sprnkoff(char); int venthopen(char); int ventfopen(char); int venthclos(char); int ventfclos(char); void tmpcontrol(void); void humcontrol(void); void wincontrol(void); void toohot(void); void toocold(void); void toohum(void); void toodry(void); void toowin(void); void alarm(char); int resetflag=0,quitflag=0; int optmp=0,ophum=0,opwin=0; int cutmp=0,cuhum=0,cuwin=0; int max=0,min=0; static int sprnk[2]; static int vents[5]; static int rads[4]; main() { while(quitflag==0) { initialize(); screen(); input(); while((resetflag==0)&&(quitflag==0)) { screen(); /* --------------------- temperature section -------------------------- */ do { cutmp=get_cur(20,9,"Temperature"); } while(cutmp==-1); max=min=0; max=hilimit(optmp); min=lolimit(optmp); tmpcontrol(); /* --------------------- humidity section --------------------------- */ if((quitflag==0)&&(resetflag==0)) { screen(); do { cuhum=get_cur(20,9,"Humidity"); } while(cuhum==-1); max=min=0; max=hilimit(ophum); min=lolimit(ophum); humcontrol(); } /*--------------------- draught section ----------------------------*/ if((quitflag==0)&&(resetflag==0)) { screen(); do { cuwin=get_cur(20,9,"Draught"); } while(cuwin==-1); max=min=0; max=hilimit(opwin); min=lolimit(opwin); wincontrol(); } /*-------------------------------------------------------------------*/ } /* end of quit & reset loop */ } /* end off quit loop */ } /* end of main */ /*---------------- Clear screen and flush keyboard buffer -----------*/ void OpenScreen(void) { CLS; fflush(stdin); } /*------------------------ display screen ----------------------------*/ void screen(void) { OpenScreen(); putchar(26); gotoxy(23,1); printf("***** Green House Status *****"); gotoxy(9,3); printf("Sprinklers Radiators Vents"); gotoxy(9,5); printf("SP1 SP2 R1 R2 R3 R4 V1 V2 V3 V4 V5"); gotoxy(9,6); printf("--- --- -- -- -- -- -- -- -- -- --"); gotoxy(9,7); printf(" %d %d %d %d %d %d %d %d %d %d %d", sprnk[0],sprnk[1],rads[0],rads[1],rads[2],rads[3],vents[0],vents[1],vents[2],vents[3],vents[4]); gotoxy(9,11); printf(" Optimum Optimum Optimum"); gotoxy(9,12); printf("Temperature Humidity Draught"); gotoxy(9,13); printf(" %2d %2d %2d", optmp,ophum,opwin); gotoxy(9,16); printf(" Current Current Current"); gotoxy(9,17); printf("Temperature Humidity Draught"); gotoxy(9,18); printf(" %2d %2d %2d", cutmp,cuhum,cuwin); gotoxy(9,22); printf("Key: Rads/Sprnk 0=Off,1=On. Vents 0=Shut,1/2=Half/Full Open."); } /*----------------------- get optimum settings ----------------------*/ int get_opt(int x,int y,char *strng,int min,int max) { char ip[10]; int op; gotoxy(x,y); printf(" "); gotoxy(x,y); printf("Enter Optimum %s (%d-%d) : ",strng,min,max); fflush(stdin); gets(ip); op=inv_opt(ip,min,max); return op; } /*-------------- test for invalid optimum settings ------------------*/ int inv_opt(char *strng,int min,int max) { int op; char *p; p=strng; while(*p!=NULL) { if(!(isdigit(*p))) return 0; p++; } op=atoi(strng); if((op<min)||(op>max)) { return 0; } else return op; } /*-------------------- get current settings ------------------------*/ int get_cur(int x,int y,char *strng) { char ip[10]; int op; gotoxy(x,y); printf(" "); gotoxy(x,y); printf("Enter Current %s (Q)uit or (R)eset : ",strng); fflush(stdin); gets(ip); op=inv_cur(ip); return op; } /*-------------------- test for quit / reset or setting --------------*/ int inv_cur(char *strng) { int op; char *p; p=strng; while(*p!=NULL) { if((*p=='q')||(*p=='Q')) { quitflag=1; exit(); } else if((*p=='r')||(*p=='R')) { resetflag=1; } else if(!(isdigit(*p))) return -1; p++; } op=atoi(strng); return op; } /*---------------------- Initialization ----------------------------*/ void initialize(void) { min=max=0; resetflag=quitflag=0; optmp=ophum=opwin=0; cutmp=cuhum=cuwin=0; sprnk[0]=sprnk[1]=0; rads[0]=rads[1]=rads[2]=rads[3]=0; vents[0]=vents[1]=vents[2]=vents[3]=vents[4]=0; } /*---------------------- get user input ------------------------------*/ void input(void) { do { optmp=get_opt(20,9,"Temperature",5,99); } while(optmp==0); do { ophum=get_opt(20,9,"Humidity",5,99); } while(ophum==0); do { opwin=get_opt(20,9,"Draught",5,20); } while(opwin==0); } /*--------------------------- hi-limit --------------------------------*/ int hilimit(int opt) { int op1,op2; if(opt<10) { op1=opt+2; return op1; } if(opt>=10) { op2=(opt+(opt*0.1)+1); return op2; } } /*--------------------------- lo-limit ------------------------------*/ int lolimit(int opt) { int op1,op2; if(opt<10) { op1=opt-2; return op1; } if(opt>=10) { op2=(opt-(opt*0.1)); return op2; } } /*---------------------- attempt radiator on --------------------------*/ int radon(void) { int i=0; for(i=0;i<4;i++) { if(rads[i]==0) { rads[i]=1; cutmp=cutmp+2; return 1; } } return 0; } /*--------------------- attempt radiator off -------------------------*/ int radoff(void) { int i=0; for(i=0;i<4;i++) { if(rads[i]==1) { rads[i]=0; cutmp=cutmp-2; return 1; } } return 0; } /*------------------- attempt turn sprinkler on -----------------------*/ int sprnkon(char mode) { int i=0; for(i=0;i<2;i++) { if(sprnk[i]==0) { sprnk[i]=1; if(mode=='t') cutmp=cutmp-2; if(mode=='h') cuhum=cuhum+2; return 1; } } return 0; } /*------------------- attempt turn sprinkler off ----------------------*/ int sprnkoff(char mode) { int i=0; for(i=0;i<2;i++) { if(sprnk[i]==1) { sprnk[i]=0; if(mode=='t') cutmp=cutmp+2; if(mode=='h') cuhum=cuhum-2; return 1; } } return 0; } /*---------------------- attempt 1/2 open vent -----------------------*/ int venthopen(char mode) { int i=0; for(i=0;i<5;i++) { if(vents[i]==0) { vents[i]=1; if(mode=='t') cutmp=cutmp-1; if(mode=='h') cuhum=cuhum-1; return 1; } } return 0; } /*-------------------- attempt fully open vent -----------------------*/ int ventfopen(char mode) { int i=0; for(i=0;i<5;i++) { if(vents[i]==1) { vents[i]=2; if(mode=='t') cutmp=cutmp-1; if(mode=='h') cuhum=cuhum-1; return 1; } } return 0; } /*-------------------- attempt 1/2 close vent -----------------------*/ int venthclos(char mode) { int i=0; for(i=0;i<5;i++) { if(vents[i]==2) { vents[i]=1; if(mode=='t') cutmp=cutmp+1; if(mode=='h') cuhum=cuhum+1; if(mode=='d') cuwin=cuwin-1; return 1; } } return 0; } /*-------------------- attempt fully close vent -----------------------*/ int ventfclos(char mode) { int i=0; for(i=0;i<5;i++) { if(vents[i]==1) { vents[i]=0; if(mode=='t') cutmp=cutmp+1; if(mode=='h') cuhum=cuhum+1; if(mode=='d') cuwin=cuwin-1; return 1; } } return 0; } /*--------------------- temperature control ------------------------*/ void tmpcontrol(void) { if(cutmp>=max) toohot(); else if(cutmp<=min) toocold(); } /*--------------------- humidity control ---------------------------*/ void humcontrol(void) { if(cuhum>=max) toohum(); else if(cuhum<=min) toodry(); } /*--------------------- draught control ----------------------------*/ void wincontrol(void) { if(cuwin>=max) toowin(); } /*---------------------- too hot, Phew !!! ------------------------*/ void toohot(void) { while((cutmp>=max)&&(resetflag==0)) { if(radoff()==0) if(venthopen('t')==0) if(ventfopen('t')==0) if(sprnkon('t')==0) alarm('t'); } } /*-------------------- too cold, Brrrr !!! ---------------------------*/ void toocold(void) { while((cutmp<=min)&&(resetflag==0)) { if(venthclos('t')==0) if(ventfclos('t')==0) if(sprnkoff('t')==0) if(radon()==0) alarm('c'); } } /*------------------------ too humid -------------------------------*/ void toohum(void) { while((cuhum>=max)&&(resetflag==0)) { if(sprnkoff('h')==0) if(venthopen('h')==0) if(ventfopen('h')==0) alarm('h'); } } /*----------------------- too dry ----------------------------------*/ void toodry(void) { while((cuhum<=min)&&(resetflag==0)) { if(sprnkon('h')==0) if(venthclos('h')==0) if(ventfclos('h')==0) alarm('d'); } } /*-------------------------- too win --------------------------------*/ void toowin(void) { while((cuwin>=max)&&(resetflag==0)) { if(venthclos('d')==0) if(ventfclos('d')==0) alarm('w'); } } /*---------------------------- alarm -------------------------------*/ void alarm(char mode) { putchar(26); gotoxy(30,11); printf("*** Warning ! ***"); gotoxy(34,13); if(mode=='t'){gotoxy(34,13);printf("Too Hot !");} if(mode=='d'){gotoxy(34,13);printf("Too Dry !");} if(mode=='c'){gotoxy(33,13);printf("Too Cold !");} if(mode=='h'){gotoxy(33,13);printf("Too Humid !");} if(mode=='w'){gotoxy(32,13);printf("Too Draughty !");} gotoxy(25,15); printf("Environment Limits Exceeded !"); gotoxy(28,17); printf("Attend Fault and Reset !"); resetflag=1; getch(); }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
5 min ago | 0.06 KB
Untitled
1 hour ago | 7.75 KB
Untitled
3 hours ago | 16.07 KB
Untitled
7 hours ago | 9.93 KB
Inoreader custom CSS
CSS | 8 hours ago | 0.20 KB
Untitled
9 hours ago | 8.11 KB
Untitled
11 hours ago | 9.50 KB
Untitled
13 hours ago | 7.48 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!