NO

Author Topic: Having trouble performing common math........  (Read 3611 times)

buckbuilt03

  • Guest
Having trouble performing common math........
« on: July 23, 2011, 12:23:57 PM »
Man, I'm getting sooo fed-up with these "POLINK errors" and I'm also having trouble performing  basic math functions...even with the math header file included.  I'm trying to calculate parallel resistance within a while loop (that's within a switch statement).  Any advice is welcome....Thank you.


#include <stdio.h>
#include <math.h>
#define PI 3.14159


/*This program will display an options menu which will allow the user to choose from various resistor properties*/
int
main (void) {
int number;
double par_resistance, sum;
   sum = 0.0;
   
   printf("1  Calculate Series Resistance\n\n2  Calculate Parallel Resistance\n\n3  Calculate User-Needed Resistor With Given Resistance\n\n4  Rectangular and Polar Form of Series RC Circuit\n\n5  Rectangular and Polar Form of Series RL Circuit\n\n6  Convert From Rectangular to Polar\n\n7  Convert From Polar to Rectangular\n\n8  Calculate Cut-Off Frequency of RC Circuit\n\n\n\n\n\n");
       printf("Please Enter Number Choice...\n\n\n");
   scanf("%d", &number);
switch (number) {
         case 1:
                  printf("Welcome to:  Calculating Series Resistance\n\n\n\n");
         break;
         case 2:
                  printf("Welcome to:   Calculating Parallel Resistance\n\n\n\n");

                     printf("\n\nEnter values one at a time..Enter -11 to quit:\n\n");
                        scanf("%lf", &par_resistance);
                  
                     while (par_resistance > 0.0)  {                         
                           sum = sum + (1.0/par_resistance);
                        printf("_", &par_resistance);
                        scanf("%lf", &par_resistance);      
                                                       sum = 1.0/sum;    }
                        
                        printf("\n\nThe total parallel resistance is....%f\n\n", &sum);     
                  
         break;
                     
         case 3:
                    printf("Welcome to:   Calculating User-Needed Resistor\n\n\n\n");
         break;
         case 4:
                  printf("Welcome to:   Rectangular and Polar Form of Series RC Circuit\n\n\n\n");
         break;
         case 5:
                  printf("Welcome to:   Rectangular and Polar Form of Series RL Citcuit\n\n\n\n");
         break;
         case 6:
                  printf("Welcome to:   Converting from Rectangular to Polar Form\n\n\n\n");
         break;
         case 7:
                  printf("Welcome to:   Converting from Polar to Rectangular Form\n\n\n\n");
         break;
         case 8:
                  printf("Welcome to:   Callculating Cut-Off Frequency of RC Circuit\n\n\n\n");
         break;
  }
return (0); 
 }

CommonTater

  • Guest
Re: Having trouble performing common math........
« Reply #1 on: July 23, 2011, 01:14:59 PM »
What POLINK errors are you getting?  If it's not finding the Pelles-C libraries it may be a problem in your installation or the path strings under tools->options->Folders... check they are correct and the folders actually exist.  Also if you do not start a project from one of the wizards in the File->New->Project folder, your system paths will not be correctly set.

Also as a general hint about readability of code, you should break up that run-on printf() into several smaller statements (one per item?).  You should also lay off the newlines ... People don't tend to read or understand widely spaced text very well...



Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Having trouble performing common math........
« Reply #2 on: July 23, 2011, 01:24:17 PM »
In addition you may select all the code and use the formatting tool of the IDE to bring it into shape.
This can be done by using the context menu of the IDE and selecting Convert to => Formated C code, example output below.

Using a code box by hitting the #-button in the message editor helps for a better display in the forum too.

For the best help you can get, attach a source code package of your project, which you can get through the menu item Project => ZIP files.
This way we all have the same environment to reproduce your error messages.

Code: [Select]
#include <stdio.h>
#include <math.h>
#define PI 3.14159


/*This program will display an options menu which will allow the user to choose from various resistor properties*/
int main(void)
{
    int number;
    double par_resistance, sum;
    sum = 0.0;

    printf("1  Calculate Series Resistance\n\n2  Calculate Parallel Resistance\n\n3  Calculate User-Needed Resistor With Given Resistance\n\n4  Rectangular and Polar Form of Series RC Circuit\n\n5  Rectangular and Polar Form of Series RL Circuit\n\n6  Convert From Rectangular to Polar\n\n7  Convert From Polar to Rectangular\n\n8  Calculate Cut-Off Frequency of RC Circuit\n\n\n\n\n\n");
    printf("Please Enter Number Choice...\n\n\n");
    scanf("%d", &number);
    switch (number)
    {
        case 1:
            printf("Welcome to:  Calculating Series Resistance\n\n\n\n");
            break;
        case 2:
            printf("Welcome to:   Calculating Parallel Resistance\n\n\n\n");

            printf("\n\nEnter values one at a time..Enter -11 to quit:\n\n");
            scanf("%lf", &par_resistance);

            while (par_resistance > 0.0)
            {
                sum = sum + (1.0 / par_resistance);
                printf("_", &par_resistance);
                scanf("%lf", &par_resistance);
                sum = 1.0 / sum;
            }

            printf("\n\nThe total parallel resistance is....%f\n\n", &sum);

            break;

        case 3:
            printf("Welcome to:   Calculating User-Needed Resistor\n\n\n\n");
            break;
        case 4:
            printf("Welcome to:   Rectangular and Polar Form of Series RC Circuit\n\n\n\n");
            break;
        case 5:
            printf("Welcome to:   Rectangular and Polar Form of Series RL Citcuit\n\n\n\n");
            break;
        case 6:
            printf("Welcome to:   Converting from Rectangular to Polar Form\n\n\n\n");
            break;
        case 7:
            printf("Welcome to:   Converting from Polar to Rectangular Form\n\n\n\n");
            break;
        case 8:
            printf("Welcome to:   Callculating Cut-Off Frequency of RC Circuit\n\n\n\n");
            break;
    }
    return (0);
}
---
Stefan

Proud member of the UltraDefrag Development Team

buckbuilt03

  • Guest
Re: Having trouble performing common math........
« Reply #3 on: July 23, 2011, 01:47:45 PM »
ya, i need to clean it up...thanks fpr formatting tip...will try.  I get polink when i debug...console program output opens and causes the error.  went to task mgr and no previous .c are running.  any idea with the inverse of the inveerse math???

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Having trouble performing common math........
« Reply #4 on: July 23, 2011, 02:52:29 PM »
I was creating an empty 32-bit console project and added the code to it.

The only thing needed to be changed to successfully compile was line 35 of the formatted code.
Code: [Select]
printf("\n\nThe total parallel resistance is....%f\n\n", sum);
Using PellesC v6.50.8 RC4 Win64.

Did not try debugging.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: Having trouble performing common math........
« Reply #5 on: July 23, 2011, 03:13:32 PM »
ya, i need to clean it up...thanks fpr formatting tip...will try.  I get polink when i debug...console program output opens and causes the error.  went to task mgr and no previous .c are running.  any idea with the inverse of the inveerse math???

Parallel resistance is the sum of the reciprocals of all values, so you are calculating it correctly...

I also got it to run by removing the & from the line printing the total parallel resistance...  That would cause an access error since printf() is not expecting a pointer.