forum-msg-id-133148-edit

Original date:2018-11-12 06:18:25 Edited by: Senator Subject: electrical calculations

More of my "eternal novice" stuff:

-- 
--  elecCalc.ex 
-- 
include std/console.e 
include std/graphics.e 
include std/text.e 
 
constant Options = sprintf("%s", { 
""" 

 
  Electrical Formulas 
 
   1.  W = V2/R 
   2.  W = R*A2 
   3.  W = V*A 
 
   4.  A = sqrt(W/R)   
   5.  A = W/V 
   6.  A = V/R 
   
   7.  V = R*A 
   8.  V = W/A 
   9.  V = sqrt(W*R) 
  10.  V = Wh/Ah 
   
  11.  R = V/A 
  12.  R = V2/W 
  13.  R = W/A2 
   
  14.  Wh = V*Ah 
  15.  Wh = mAh*(V/1000) 
   
  16.  Ah = Wh/V 
   
  0 -- quit 
   
 """ 

 }) 
  
atom W, A, V, Wh, Ah, mAh, R, hp=745.7 
procedure set_values( sequence g={"", 0, "", 0} ) 
 puts(1,"\n") 
	for i = 1 to 4 by 2  do  
	g[i+1]=prompt_number("\t\t"&g[i] &" = ",{}) 
		if equal("W",         g[i]) then     W  = g[i+1]  
		elsif equal("A",      g[i]) then     A  = g[i+1] 
		elsif equal("V",      g[i]) then     V  = g[i+1] 
		elsif equal("Wh",     g[i]) then     Wh = g[i+1] 
		elsif equal("Ah",     g[i]) then     Ah = g[i+1] 
		elsif equal("mAh",    g[i]) then    mAh = g[i+1] 
		elsif equal("R",      g[i]) then      R = g[i+1] 
		end if 
	end for 
end procedure 
 
procedure main() 
sequence Rs, SS="%s = %.4g", HP=" (%.4g Hp)" 
integer RUN=1 
bk_color(BLACK)  text_color(GREEN) clear_screen() 
while RUN do RUN = prompt_number(Options&" Select #: ", {0,16}) 
	switch RUN do 
	case 1 then display("\t1. W = V2/R") set_values({"V",0, "R",0}) W=power(V,2)/R Rs=sprintf(SS & HP, {"W",W,W/hp}) 
	case 2 then display("\t2. W = R*A2") set_values({"R",0,"A",0}) W=R*power(A,2)  Rs=sprintf(SS & HP,{"W", W,W/hp}) 
	case 3 then display("\t3. W = V*A") set_values({"V",0,"A",0})  W=V*A  Rs=sprintf(SS & HP,{"W",W,W/hp}) 
	case 4 then display("\t4. A  = power(W/R,.5)") set_values({"W",0,"R",0})  Rs=sprintf(SS,{"A",sqrt(W/R)}) 
	case 5 then display("\t5. A  = W/V") set_values({"W",0,"V",0})  Rs=sprintf(SS,{"A",W/V}) 
	case 6 then display("\t6. A = V/R") set_values({"V",0,"R",0}) Rs=sprintf(SS,{"A",V/R}) 
	case 7 then display("\t7. V = R*A") set_values({"R",0,"A",0}) Rs=sprintf(SS,{"V",R*A}) 
	case 8 then display("\t8. V = W/A") set_values({"W",0,"A",0}) Rs=sprintf(SS,{"V",W/A}) 
	case 9 then display("\t9. V = power(W*R, .5)") set_values({"W",0,"R",0}) Rs=sprintf(SS,{"V", sqrt(W*R)}) 
	case 10 then display("\t10. V= Wh/Ah")  set_values({"Wh",0,"Ah",0}) Rs=sprintf(SS,{"V",Wh/Ah})  
	case 11 then display("\t11. R = V/A") set_values({"V",0,"A",0}) Rs=sprintf(SS,{"R",V/A}) 
	case 12 then display("\t12. R = V2/W") set_values({"V",0,"W",0})  Rs=sprintf(SS,{"R",power(V,2)/W}) 
	case 13 then display("\t13. R = W/A2") set_values({"W",0,"A",0})  Rs=sprintf(SS,{"R",W/power(A,2)}) 
	case 14 then display("\t14. Wh = V*Ah") set_values({"V",0,"Ah",0}) Rs=sprintf(SS,{"Wh",V*Ah}) 
	case 15 then display("\t15. Wh = mAh*(V/1000)") set_values({"mAh",0,"V",0}) Rs=sprintf(SS,{"Wh",mAh*(V/1000)}) 
	case 16 then display("\t16. Ah = Wh/V") set_values({"Wh",0,"V",0})  Rs=sprintf(SS,{"Ah",Wh/V})			 
	case 0 then  abort(0)		 
	end switch 
	text_color(YELLOW) display("\t\t"&Rs) text_color(GREEN) 
end while 
end procedure 
main() 
 
Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu