Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Header Files
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- #include <assert.h>
- #include "get_input.h"
- ///////////////////////////////////////
- //===================================//
- // Function Declarations //
- //===================================//
- ///////////////////////////////////////
- void clear_screen();
- void output_print_dkc(int topology, double effective_resistance, double effective_voltage, double effective_current);
- ///////////////////////////////////////
- //===================================//
- // Main Function //
- //===================================//
- ///////////////////////////////////////
- int main()
- {
- ///////////////////////////////////////
- //===================================//
- // Variable Declarations //
- //===================================//
- ///////////////////////////////////////
- //Input Values
- int topology;
- int source_type;
- double source_value;
- int resist_no;
- //Declaration of Resistor Value arrays |down|
- //Effective Values
- double effective_resistance;
- double effective_voltage;
- double effective_current;
- ///////////////////////////////////////
- //===================================//
- // Variable Initialization //
- //===================================//
- ///////////////////////////////////////
- /*===================================
- || Input Values ||
- ===================================*/
- //Topology
- topology = get_topology();//get_input.c
- printf("\n");
- //Source
- source_type = get_source_type();//get_input.c
- printf("\n");
- source_value = get_source_value();//get_input.c
- printf("\n");
- //Resistors
- resist_no = get_resist_no();//get_input.c
- printf("\n");
- printf("DEBUG: %d\n",resist_no);
- //Declaration of Resistor Value arrays |here|
- double resistor_values[resist_no];
- printf("DEBUG: %d\n",resist_no);
- //Resistor Values
- int i;
- printf("Please Input the Values of each Resistor: DEBUG: %.6f",get_resist_value());
- for(i=0;i<resist_no;i++){
- printf("\n\tPlease input the value of Resistor #%d: ",i+1);
- resistor_values[i]=get_resist_value(); //Here's the problem============================================<<<<<<<<<<<<<<+++++
- }
- printf("\n");
- printf("DEBUG: Topology: %d\n\tSourceType: %d\n\tSourceValue: %.2f\n\tResistanceNumber: %d\n",topology,source_type,source_value,resist_no);
- printf("DEBUG: resistor_values[0]: %d\n", resistor_values[0]);
- printf("DEBUG: resistor_values[1]: %d\n", resistor_values[1]);
- /*===================================
- || Effective Values ||
- ===================================*/
- //Effective Resistance
- effective_resistance = get_effective_resistance(resistor_values,topology,resist_no);//circuits.c
- printf("DEBUG: effect_restPOST: %.6f\n",effective_resistance);
- //Effective Voltage
- effective_voltage = get_effective_vc(effective_resistance,source_type,source_value,0);//circuits.c
- printf("DEBUG: effect_voltPOST: %.6f\n",effective_voltage);
- //Effective Current
- effective_current = get_effective_vc(effective_resistance,source_type,source_value,1);//circuits.c
- printf("DEBUG: effect_currPOST: %.6f\n",effective_current);
- ///////////////////////////////////////
- //===================================//
- // Console Out Printing //
- //===================================//
- ///////////////////////////////////////
- /*===================================
- || Output Function ||
- ===================================*/
- output_print_dkc(topology, effective_resistance, effective_voltage, effective_current);
- /*===================================
- || Individual Resistance ||
- ===================================*/
- if(topology!=3){
- printf("Do you want to compute for the individual voltage and current of a resistor?(y/n)");
- if(get_bool_input()==1){
- //Making Arrays of our current information...
- int integerArray[3+resist_no];
- double doubleArray[4];
- integerArray[0] = topology;
- integerArray[1] = source_type;
- integerArray[2] = resist_no;
- int i;
- for(i=0;i<resist_no;i++){
- doubleArray[i+4] = resistor_values[i];
- }
- doubleArray[0] = effective_resistance;
- doubleArray[1] = effective_voltage;
- doubleArray[2] = effective_current;
- doubleArray[3] = source_value;
- /*List of indexes
- intArray
- 0 - topology
- 1 - source_type
- 2 - resist_no
- 3+resist_no - resistor_values
- doubleArray
- 0 - effective_resistance
- 1 - effective_voltage
- 2 - effective_current
- 3 - source_value
- */
- get_individual_resistor_values(integerArray,doubleArray);
- }
- }
- //Goodbye
- printf("\n\nThank you for using the Simplified Electric Circuit Simulator!\nExiting...");
- return 0;
- }
- ///////////////////////////////////////
- //===================================//
- // Function Definitions //
- //===================================//
- ///////////////////////////////////////
- void clear_screen(){
- int i;
- for(i=0;i<40;i++){printf("\n");}
- }
- void output_print_dkc(int topology, double effective_resistance, double effective_voltage, double effective_current){
- //Printing Effective Values
- printf("The effective Resistance of the Circuit is: %.6f\nEffective Voltage: %.6f\nEffective Current: %.6f\n",effective_resistance,effective_voltage,effective_current);
- //Printing Circuit Topology
- switch(topology){
- case 1:
- printf("Series Circuit Detected.");
- break;
- case 2:
- printf("Parallel Circuit Detected.");
- break;
- case 3:
- printf("Ladder Circuit Detected. \n\t Note: It is not possible to calculate for individual values.");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement