Thread: re:array of notation (full code)

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    Unhappy array notation help

    hi, i trying to list out the array of power,amps,res
    and vots input by user.
    But only available to list out the first input of power,amps..etc.
    Second input gave me 0s.

    thanks in advance...

    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define SIZE 50



    char input[SIZE];
    int choice;
    float vots[SIZE],amps[SIZE],res[SIZE],power[SIZE],*v,*i,*r,*p;

    *v=vots;
    *i=amps;
    *r=res;
    *p=power;

    void main()
    {
    some codes...
    }
    void high_low(void)
    {
    int x,hi=0,li=0;
    float hpower,lpower;

    for (x=0; x < 2; x++)
    {

    system("cls");
    printf("\n");
    printf("\tThe calculated DC powers are:\n");
    printline();

    printf("\n\tNo.\tCurrent\t\tVoltage\t\tResistance\ tPower");
    printf("\n\t\t(amps)\t\t(volt)\t\t(ohms)\t\t(watts )\n");
    printline();

    printf("\t%2d\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n",x+1 ,*(i+x),*(v+x),*(res+x),*(power+x));
    x=x+0;
    }
    }
    void power_VI (void)

    {

    system("cls");
    printline();
    printf("\t\tDC Power calculation using Voltage and Current\n");
    printline();


    printf("\n\t\tEnter the value of voltage <vots> : ");
    gets(input);
    *v=(float)atof(input);

    printf("\t\tEnter the value of current <amps> : ");
    gets(input);
    *i=(float)atof(input);

    printf("\n\t\tThe computed values are :\n");
    *r = (*v)/(*i);
    *p = (*v**v)/(*r);

    printf("\n\t\tResistance = %.2f ohms\tDC power = %.2f watts\n", *r,*p);


    }

    void power_VR (void)

    {

    system("cls");
    printline();
    printf("\t\tDC Power calculation using Voltage and Resistance\n");
    printline();


    printf("\n\t\tEnter the value of voltage <vots> : ");
    gets(input);
    *v=(float)atof(input);

    printf("\t\tEnter the value of resistance <ohms> : ");
    gets(input);
    *r=(float)atof(input);

    printf("\n\t\tThe computed values are :\n");
    *i = (*v)/(*r);
    *p = (*i)*(*i)*(*r);

    printf("\n\t\tCurrent = %.2f amps\tDC power = %.2f watts\n", *i,*p);


    }
    void power_IR (void)

    {

    system("cls");
    printline();
    printf("\t\tDC Power calculation using Current and Resistance\n");
    printline();


    printf("\n\t\tEnter the value of current <amps> : ");
    gets(input);
    *i=(float)atof(input);

    printf("\t\tEnter the value of resistance <ohms> : ");
    gets(input);
    *r=(float)atof(input);

    printf("\n\t\tThe computed values are :\n");
    *v = (*i)*(*r);
    *p = (*v)*(*v)/(*r);

    printf("\n\t\tVoltage = %.2f ohms\tDC power = %.2f watts\n", *v,*p);


    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    re:array of notation (full code)

    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #define SIZE 50


    int menu(void);
    void printline(void);
    void power_VI(void);
    void power_VR(void);
    void power_IR(void);
    void high_low(void);


    char input[SIZE];
    int choice;
    float vots[SIZE],amps[SIZE],res[SIZE],power[SIZE],*v,*i,*r,*p;

    *v=vots;
    *i=amps;
    *r=res;
    *p=power;

    void main()
    {

    //float num1,num2;


    while(1)
    {

    choice=menu();

    switch(choice)
    {
    case '1': power_VI();

    break;
    case '2':
    power_VR();
    break;
    case '3':
    power_IR();
    break;
    case '4':
    high_low();
    break;

    case '5':
    printf("\n\t\t");
    break;
    default :
    printf("\n\t\tInvalid Key -- try again!\n");
    }
    if(choice == '5')
    break;

    printf("\n\t\tPress any key to continue!");
    getch();
    }

    }

    void high_low(void)
    {
    int x,hi=0,li=0;
    float hpower,lpower;

    for (x=0; x < 2; x++)
    {

    system("cls");
    printf("\n");
    printf("\tThe calculated DC powers are:\n");
    printline();

    printf("\n\tNo.\tCurrent\t\tVoltage\t\tResistance\ tPower");
    printf("\n\t\t(amps)\t\t(volt)\t\t(ohms)\t\t(watts )\n");
    printline();

    printf("\t%2d\t%.2f\t\t%.2f\t\t%.2f\t\t%.2f\n",x+1 ,*(i+x),*(v+x),*(res+x),*(power+x));
    x=x+0;
    }
    }
    void power_VI (void)

    {

    system("cls");
    printline();
    printf("\t\tDC Power calculation using Voltage and Current\n");
    printline();


    printf("\n\t\tEnter the value of voltage <vots> : ");
    gets(input);
    *v=(float)atof(input);

    printf("\t\tEnter the value of current <amps> : ");
    gets(input);
    *i=(float)atof(input);

    printf("\n\t\tThe computed values are :\n");
    *r = (*v)/(*i);
    *p = (*v**v)/(*r);

    printf("\n\t\tResistance = %.2f ohms\tDC power = %.2f watts\n", *r,*p);


    }

    void power_VR (void)

    {

    system("cls");
    printline();
    printf("\t\tDC Power calculation using Voltage and Resistance\n");
    printline();


    printf("\n\t\tEnter the value of voltage <vots> : ");
    gets(input);
    *v=(float)atof(input);

    printf("\t\tEnter the value of resistance <ohms> : ");
    gets(input);
    *r=(float)atof(input);

    printf("\n\t\tThe computed values are :\n");
    *i = (*v)/(*r);
    *p = (*i)*(*i)*(*r);

    printf("\n\t\tCurrent = %.2f amps\tDC power = %.2f watts\n", *i,*p);


    }
    void power_IR (void)

    {

    system("cls");
    printline();
    printf("\t\tDC Power calculation using Current and Resistance\n");
    printline();


    printf("\n\t\tEnter the value of current <amps> : ");
    gets(input);
    *i=(float)atof(input);

    printf("\t\tEnter the value of resistance <ohms> : ");
    gets(input);
    *r=(float)atof(input);

    printf("\n\t\tThe computed values are :\n");
    *v = (*i)*(*r);
    *p = (*v)*(*v)/(*r);

    printf("\n\t\tVoltage = %.2f ohms\tDC power = %.2f watts\n", *v,*p);


    }




    int menu(void)

    {
    system("cls");
    printline();
    printf("\t\tCALCULATION OF DC POWER\n");
    printline();
    printf("\t\t(1)\tUsing Voltage and Current\n");
    printf("\t\t(2)\tUsing Voltage and Resistance\n");
    printf("\t\t(3)\tUsing Current and Resistance\n");
    printf("\t\t(4)\tDisplay Highest & Lowest Power\n");
    printf("\t\t(5)\tExit\n");
    printline();
    printf("\n\t\tPlease enter your choice : ");
    return getche();
    }


    void printline (void)
    {
    int count;
    printf("\t");
    for(count=0; count<65; count++)
    {
    printf("=");
    }
    printf("\n");
    }

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Read this then edit your post to make your code readable.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM