Hi all
I have to write code that ask the user to input a current (that will be split into two currents) and then the output from the code should display the two resulting currents given two input resistors. That part I can do but my problem is I have to then take all that and create tables that gives a range of values from small to large for the resistor values and then shoots out the answers in another column. Any ideas? Il add my current codes as well. Thanks in advance

So the following code needs to be included in the bigger block below it

// Lab 3
#include "stdio.h"
#include "math.h"

int main(int arg)
{
      int I1;
      int I2;
      int I3;
      int R2;
      int R3;
      int N;      

      //power dissipation is r^2*I


      ;printf("Enter the initial current in Amps:");
      scanf("%d",&I1);

      ;printf("Enter R2 in ohms:");
      scanf("%d",&R2);

      ;printf("Enter R3 in ohms:");
      scanf("%d",&R3);

      ;printf("Enter the number of entries:");
      scanf("%d",&N);

      I2 = R3/(R2+R3)*I1;
      printf("The value of I2 is : %lf\n",I2);

      I3 = (R2/(R2+R3))*I1;
      printf("The value of I3 is : %lf\n",I3);
      ;return 0;
}
##################### 

#include <iostream>
#include <iomanip>
using namespace std;
#include "stdio.h"
#include "math.h"

int R1;
int R2;
int Iin;
int I1;
int I2;
int step_size;

void print_preliminary_message();
void input_table_specifications(int& Iin, int& R1, int& R2, int& step_size);
void print_message_echoing_input(int Iin, int R1, int R2, int step_size); 
void print_table(int Iin, int R1, int R2, int step_size); 

/* START OF MAIN PROGRAM */
int main() 
{   
    int Iin = 10;  /* for the lowest ohm entry in the table */
    int R1 = 100; 
    int R2 = 100; /* for the highest ohm entry in the table */
    int step_size = 1;   /* for the difference in ohms between entries */

    /* set the tabbing functions in iostream.h to left-justify */
    cout << setiosflags (ios::left);

    /* print a message explaining what the program does: */
    print_preliminary_message();

    /* prompt the user for table specifications in ohms: */
    input_table_specifications(Iin, R1, R2, step_size);

    /* print an appropriate message including an echo of the input: */
    print_message_echoing_input(Iin, R1, R2, step_size);

    /* Print the table (including the column headings): */
    print_table(Iin, R1, R2, step_size);

    return 0;
}
/* END OF MAIN PROGRAM */




/* START OF FUNCTION */
void print_preliminary_message()
{
    cout << "This program prints out two currents and power dissipation between them." << endl << endl;
}
/* END OF FUNCTION */   


/* START OF FUNCTION */
void input_table_specifications(int& Iin, int& I1, int& I2, int& step_size)
{
    cout << "Enter the value of " << endl;
    cout << "the current going in: ";
    cin >> Iin;
    cout << "Enter the smallest resistance for R1 resistance: ";
    cin >> R1;
    cout << "Enter the biggest resistance for R1: ";
    cin >> R2;
    cout << "Enter the total number of steps: ";
    cin >> step_size;
    cout << endl << endl;
}
/* END OF FUNCTION */


/* START OF FUNCTION */
void print_message_echoing_input(int Iin, int I1, int I2, int step_size)
{
    cout << "Resistance table from " << Iin << " Ohms" << endl;
    cout << "to " << I1 << " ohms, in steps of ";
    cout << step_size << " ohms:" << endl << endl;
}
/* END OF FUNCTION */


/* START OF FUNCTION */
void print_table(int Iin, int R1, int R2, int step_size)
{
    int fahr; 

    /* Print table heading */
    cout.width(17);
    cout << "Current 1";
    cout.width(13);
    cout << "Current 2" << "Power Dissipation" << endl << endl;

    /* set format of individual values */
    cout.precision(2); 
    cout.setf(ios::fixed); 

    /* print table from lowest_entry to highest_entry */
    for (fahr = I1 ; fahr <= I2 ; fahr += step_size) {
        cout << "   ";
        cout.width(15);
        cout.width(15);
        cout << I1 << I2 << endl;
    }
}
/* END OF FUNCTION  */

Edited 3 Years Ago by Dani: Formatting fixed

Even if somebody can help me simply to display values of I1 in column one and values of I2 in column two then that would be of great help already. If there is a shorter way of taking the first block of code and displaying two columns of currents then even better. Thanks heaps

This article has been dead for over six months. Start a new discussion instead.