Hello all,
I am learning C++ more and less by my self by online resources
and a couple books i have bought. I have been working on it for around six months now and i started with no real knowledge of programming.
This is a program i have been working on witch will calculate Volts, Ohms,
Watts, Amps, and Voltage drop.
The Voltagedrop section i am working on as a separate program that i will turn into a fuction of the main program as soon as i overcome some of my lack of knowledge and figuring out witch way works best.
This Voltagedrop portion will contain:
(2) different wire material types
(30) different wire sizes
(3) different voltage types
a user inputed wire length
a user inputed amperage
i am planning a calculation based on only the:
amperage
voltage type
distance
This is for calculating what wire size would give no more than a 3%
voltage drop for a given circut running user supplied information said above.
but here is the main program witht he basic calculations.
and below that is a snippet of the voltagedrop section...
Code:#include <iostream> #include <cstdlib> void MainMenu(); void VoltMenu(); void OhmMenu(); void WattMenu(); void AmpMenu(); void DropMenu(); void AboutMenu(); using namespace std; int main() { MainMenu(); return 0; } void MainMenu() { int choice; cout<<" VOWAD\n"; cout<<"*** Main Menu ***\n"; cout<<"[1] Calculate Volts\n"; cout<<"[2] Calculate Ohms\n"; cout<<"[3] Calculate Watts\n"; cout<<"[4] Calculate Amps\n"; cout<<"[5] Calculate Drop\n"; cout<<"[6] About Vowad\n"; cout<<"[7] Exit\n"; cout<<"Selection: "; cin>> choice; if (cin.fail()) { cin.clear(); cin.ignore(); system("clear output"); cout<<"Sorry! not a menu option\n"; MainMenu(); } if (choice == 1){ system("clear output"); VoltMenu(); } else if (choice == 2){ system("clear output"); OhmMenu(); } else if (choice == 3){ system("clear output"); WattMenu(); } else if (choice == 4){ system("clear output"); AmpMenu(); } else if (choice == 5){ system("clear output"); DropMenu(); } else if (choice == 6){ system("clear output"); AboutMenu(); } else if (choice == 7){ cout<<"You entered choice: " << choice << endl; cout<<"Exiting Vowad\n"; system("exit"); } else { system("clear output"); cout<<"Sorry! not a menu option\n"; MainMenu(); } } void VoltMenu() { float volt; float amp; float ohm; float watt; int choice; cout<<" VOWAD\n"; cout<<"*** VOLTS MENU ***\n"; cout<<"[1] Calculate Volts (watt/amp)\n"; cout<<"[2] Calculate Volts (ohm*amp)\n"; cout<<"[3] Main Menu\n"; cout<<"Selected: "; cin >> choice; if (cin.fail()) { cin.clear(); cin.ignore(); system("clear output"); cout<<"Sorry! not a menu option\n"; VoltMenu(); } if (choice == 1){ cout<<"Enter Watts: "; cin>> watt; cout<<"Enter Amps: "; cin>> amp; volt = watt / amp; ohm = volt / amp; system("clear output"); cout<<"Circut Running At: "<< watt << " Watts" << " -and- " << amp <<" Amps\n"; cout<<"Has Calculated Volts: " << volt << endl; cout<<"Has Calculated Ohms: " << ohm << endl; VoltMenu(); } else if (choice == 2){ cout<<"Enter Ohms: "; cin>> ohm; cout<<"Enter Amps: "; cin>> amp; volt = amp * ohm; watt = volt * amp; system("clear output"); cout<<"Circut Running At: "<< ohm << " Ohms" << " -and- " << amp <<" Amps\n"; cout<<"Has Calculated Volts: " << volt << endl; cout<<"Has Calculated Watts: " << watt << endl; VoltMenu(); } else if (choice == 3){ system("clear output"); MainMenu(); } } void OhmMenu() { float volt; float amp; float ohm; float watt; int choice; cout<<"*** OHMS MENU ***\n"; cout<<"[1] Calculate Ohms (volt/amp)\n"; cout<<"[2] Calculate Ohms (ohm=volt/(watt/volt=amp)\n"; cout<<"[3] Main Menu\n"; cout<<"Selected: "; cin >> choice; if (cin.fail()) { cin.clear(); cin.ignore(); system("clear output"); cout<<"Sorry! not a menu option\n"; OhmMenu(); } if (choice == 1){ cout<<"Enter Volts: "; cin>> volt; cout<<"Enter Amps: "; cin>> amp; ohm = volt / amp; watt = volt * amp; system("clear output"); cout<<"Circut Running At: "<< volt << " Volts" << " -and- " << amp <<" Amps\n"; cout<<"Has Calculated Ohms: " << ohm << endl; cout<<"Has Calculated Watts: " << watt << endl; OhmMenu(); } else if (choice == 2){ cout<<"Enter Watts: "; cin>> watt; cout<<"Enter Volts: "; cin>> volt; amp = watt / volt; ohm = volt / amp; system("clear output"); cout<<"Circut Running At: "<< watt << " Watts" << " -and- " << volt <<" Volts\n"; cout<<"Has Calculated Ohms: " << ohm << endl; cout<<"Has Calculated Running Amps: " << amp << endl; OhmMenu(); } else if (choice == 3){ system("clear output"); MainMenu(); } } void WattMenu() { float volt; float amp; float ohm; float watt; int choice; cout<<" VOWAD\n"; cout<<"*** WATTS MENU ***\n"; cout<<"[1] Calculate Watts (watt/amp)\n"; cout<<"[2] Main Menu\n"; cout<<"Selected: "; cin >> choice; if (cin.fail()) { cin.clear(); cin.ignore(); system("clear output"); cout<<"Sorry! not a menu option\n"; WattMenu(); } if (choice == 1){ cout<<"Enter Volts: "; cin>> volt; cout<<"Enter Amps: "; cin>> amp; watt = volt * amp; ohm = volt / amp; system("clear output"); cout<<"Circut Running At: "<< volt << " Volts" << " -and- " << amp <<" Amps\n"; cout<<"Has Calculated Watts: " << watt << endl; cout<<"Has Calculated Ohms: " << ohm << endl; WattMenu(); } else if (choice == 2){ system("clear output"); MainMenu(); } } void AmpMenu() { float volt; float amp; float ohm; float watt; int choice; cout<<" VOWAD\n"; cout<<"*** AMPS MENU ***\n"; cout<<"[1] Calculate Amps (ohm/volt)\n"; cout<<"[2] Calculate Amps (volt/watt)\n"; cout<<"[3] Main Menu\n"; cout<<"Selected: "; cin >> choice; if (cin.fail()) { cin.clear(); cin.ignore(); system("clear output"); cout<<"Sorry! not a menu option\n"; AmpMenu(); } if (choice == 1){ cout<<"Enter Volts: "; cin>> volt; cout<<"Enter Ohms: "; cin>> ohm; amp = volt / ohm; watt = volt * amp; system("clear output"); cout<<"Circut Running At: "<< volt << " Volts" << " -and- " << ohm <<" Ohms\n"; cout<<"Has Calculated Amps: " << amp << endl; cout<<"Has Calculated Watts: " << watt << endl; AmpMenu(); } else if (choice == 2){ cout<<"Enter Watts: "; cin>> watt; cout<<"Enter Volts: "; cin>> volt; amp = watt / volt; ohm = volt / amp; system("clear output"); cout<<"Circut Running At: "<< watt << " Watts" << " -and- " << volt <<" Volts\n"; cout<<"Has Calculated Ohms: " << ohm << endl; cout<<"Has Calculated Amps: " << amp << endl; AmpMenu(); } else if (choice == 3){ system("clear output"); MainMenu(); } } void DropMenu() { cout<<" Not there yet but i am working on this part :(\n"; MainMenu(); } void AboutMenu() { cout<<" *** Smother Kitten Software ***\n"; cout<<" *** Vowad ***\n"; cout<<" system: win32\n"; cout<<" version: 0.2\n"; cout<<" by: Jacob K Mcgrath\n"; cout<<"\n"; cout<<" A electrical calculator\n"; cout<<" written in C++ on a Linux box\n"; MainMenu(); }
Code:#include <iostream> #include <cstdlib> #include <cstring> void Drop(); using namespace std; int main() { Drop(); return EXIT_SUCCESS; } void Drop() { string Copper; string Aluminum; float materialdata[2] = {12.9, 21.2}; float voltagedata[3] = {1, 0.5, .866}; int kcmildata[30] = {1620, 2560, 4110, 6530, 10380, 16510, 26240, 41740, 52620, 66360, 83690, 105600, 133100, 167800, 211600, 250000, 300000, 350000, 400000, 500000, 600000, 700000, 750000, 800000, 900000, 1000000, 1250000, 1500000, 1750000, 2000000}; int lenght; int amperes; float voltdrop; float voltdroppercent; float material; float voltage; int kcmil; int input1; int input2; cout<<" VOWAD\n"; cout<<"*** VOLTAGE DROP MENU ***\n"; cout<<"[1] Copper\n"; cout<<"[2] Aluminum\n"; cout<<"[3] Main Menu\n"; cout<<"Selected: "; cin>> input1; if (cin.fail()) { cin.clear(); cin.ignore(); cout<<"Please try again\n"; Drop(); } else if (input1 == 1){ material = materialdata[0]; cout<<" copper constant is: " << material << endl; } else if (input1 == 2){ material = materialdata[1]; cout<<" aluminum constant is: " << material << endl; } else if (input1 == 3){ system("clear output"); Drop(); } cout<<"Select Wire\n"; cout<<"[1] 18 AWG [16] 250 kcmil [31] Voltage Drop Menu\n"; cout<<"[2] 16 AWG [17] 350 kcmil \n"; cout<<"[3] 14 AWG [18] 400 kcmil \n"; cout<<"[4] 12 AWG [19] 450 kcmil \n"; cout<<"[5] 10 AWG [20] 500 kcmil \n"; cout<<"[6] 8 AWG [21] 600 kcmil \n"; cout<<"[7] 6 AWG [22] 700 kcmil \n"; cout<<"[8] 4 AWG [23] 750 kcmi \n"; cout<<"[9] 3 AWG [24] 800 kcmil \n"; cout<<"[10] 2 AWG [25] 900 kcmil \n"; cout<<"[11] 1 AWG [26] 1000 kcmil \n"; cout<<"[12] 1/0 AWG [27] 1250 kcmil \n"; cout<<"[13] 2/0 AWG [28] 1500 kcmil \n"; cout<<"[14] 3/0 AWG [29] 1750 kcmil \n"; cout<<"[15] 4/0 AWG [30] 2000 kcmil \n"; cout<<"Selected: "; cin>> input2; if (cin.fail()) { cin.clear(); cin.ignore(); cout<<"Please try again\n"; Drop(); } else if (input2 == 1){ kcmil = kcmildata[0]; cout<< kcmil << endl; } else if (input2 == 2){ kcmil = kcmildata[1]; cout<< kcmil << endl; } else if (input2 == 3){ kcmil = kcmildata[2]; cout<< kcmil << endl; } else if (input2 == 4){ kcmil = kcmildata[3]; cout<< kcmil << endl; } else if (input2 == 5){ kcmil = kcmildata[4]; cout<< kcmil << endl; } else if (input2 == 6){ kcmil = kcmildata[5]; cout<< kcmil << endl; } else if (input2 == 7){ kcmil = kcmildata[6]; } else if (input2 == 8){ kcmil = kcmildata[7]; } else if (input2 == 9){ kcmil = kcmildata[8]; } else if (input2 == 10){ kcmil = kcmildata[9]; } else if (input2 == 11){ kcmil = kcmildata[10]; } else if (input2 == 12){ kcmil = kcmildata[11]; } else if (input2 == 13){ kcmil = kcmildata[12]; } else if (input2 == 14){ kcmil = kcmildata[13]; } else if (input2 == 15){ kcmil = kcmildata[14]; } else if (input2 == 16){ kcmil = kcmildata[15]; } else if (input2 == 17){ kcmil = kcmildata[16]; } else if (input2 == 18){ kcmil = kcmildata[17]; } else if (input2 == 19){ kcmil = kcmildata[18]; } else if (input2 == 20){ kcmil = kcmildata[19]; } else if (input2 == 21){ kcmil = kcmildata[20]; cout<< kcmil << endl; } else if (input2 == 22){ kcmil = kcmildata[21]; cout<< kcmil << endl; } else if (input2 == 23){ kcmil = kcmildata[22]; cout<< kcmil << endl; } else if (input2 == 24){ kcmil = kcmildata[23]; cout<< kcmil << endl; } else if (input2 == 25){ kcmil = kcmildata[24]; cout<< kcmil << endl; } else if (input2 == 26){ kcmil = kcmildata[25]; cout<< kcmil << endl; } else if (input2 == 27){ kcmil = kcmildata[26]; cout<< kcmil << endl; } else if (input2 == 28){ kcmil = kcmildata[27]; cout<< kcmil << endl; } else if (input2 == 29){ kcmil = kcmildata[28]; cout<< kcmil << endl; } else if (input2 == 30){kcmil = kcmildata[29]; cout<< kcmil << endl; } else if (input2 == 31){ system("clear output"); Drop(); } cout<<"i have a poopy but\n"; }
as you see i am just getting started and was wondering if i could use case switches instead of the *if else if loops ?
i used case switches before and i dont even know why i strayed from that option LOL
another thing i was wondering is if i was using array,s somewhat correctly in relating to
the menu input in the voltage drop program
else if (input2 == 30){kcmil = kcmildata[29]; }
-and-
else if (input1 == 2){
material = materialdata[1]; }
it seems to work for now but i think i will run into problems later
let me know if there is a better way other than what i can see at the moment
not so much solve the problem but point me in a given direction so i can do the trial by fire route
ty
heinola