Thread: Simple program help

  1. #1
    Registered User
    Join Date
    Mar 2008

    Simple program help

    Ok this shouldn't take too long to fix, simple program for working out resistance and voltage for some amplifier...

    #include <stdio.h>
    #define Vc (5.5);
    #define Ve (1.1);
    #define Vin (0.075);       /* Voltages */
    #define Hfe (100);
    int main(void)
    	float Vout, R1, R2, R3, R4;
    	float Ic, Vcc;
    	float Ib, Vb, Ks;
    	/* Enter the current, from 2e-3 to 5e-3 */
    	printf("Enter Ic: ");
    	scanf("%f", &Ic);
            /* Enter the voltage, 9.0, 10.0 or 12.0 */
    	printf("Enter Vcc: ");
    	scanf("%f", &Vcc);
            Ib = Ic / Hfe;
    	R1 = (Vcc - Vc) / (Ic);
    	R2 = (Ve / Ic + Ib) ;
    	Vb = 0.7 + Ve;
    	R3 = (Vcc - Vb)/ (6 * Ib);
    	R4 = Vb	/ (5 * Ib);	   
    	Ks= R1/R2; 
    	Vout = Ks * Vin;
    	printf("R1= %6.0f Ohms \n", R1);
    	printf("R2= %6.0f Ohms \n", R2);
    	printf("R3= %6.0f Ohms \n", R3);
    	printf("R4= %6.0f Ohms \n", R4);
    	printf("Vout= %3.1f  V \n", Vout);

    Ok, the green lines are the ones I'm having trouble with, the compiler says "error: expected ')' before ';' token" for both the lines
    And also for the red lines, if I swap them around like so
    Vb = Ve + 0.7
    Vout = Vin * Ks
    The compiler says "Warning: statement with no effect" and "error: invalid type of 'unary *' " respectively. But if I have them the way I do as above, it works fine.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    #defines and semicolons; don't mix.

  3. #3
    Registered User
    Join Date
    Mar 2008
    haha, wow, I can't believe I missed that. I don't even know why I put them in there
    Thanks for the help

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Also, it's good to have everything for the pre-processor in caps -- it makes it easier to read.

    For example, I'd think 'Vin' is a variable name at first glance. Constants rather than defines would do well here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 01:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM