Thread: guidance with writing program

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    guidance with writing program

    Hi,

    I am trying to write my first c program for an assignment, so I'm not lookin for someone to write it for me I know that i'm missing some things or steps in the code, but can't work out what exactly. As far as I can tell, I have declared the constants and variables and assigned correct data types where necessary, but i'm not sure about the way I have set out the calculations and think this is where the problem could be. The program is supposed to give the value of several different resistors after the user inputs two variable values. Any guidance would be appreciated.


    Regards, phoenixg

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Other than a mismatched comment marker (/* missing) it looks pretty good.

    Solving for a common emitter amplifier is pretty straight forward...

    Is there a specific problem?

    (As a matter of custom... please post your code in the open using [ code] [/code] tags in future.)

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    	float R1, R2, R3, R4;
           ....
    	printf("Resistors:\n");
    	printf("R1 = %10d ohm\n", R1); 
    	printf("R2 = %10d ohm\n", R2);
    	printf("R3 = %10d ohm\n", R3);
    	printf("R4 = %10d ohm\n\n", R4);
    You should not print float variable with %d.
    Compiler cannot promote type for variadic arg function like printf,scanf,...
    If you have sin( 3 ). 3 is of course type int. But since compiler can see prototype of sin ( double sin(double); ) int 3 will be promoted to correct type.
    But for variadic arg function, no such thing can be performed.
    printf(3): formatted output conversion - Linux man page
    Last edited by Bayint Naung; 03-26-2011 at 05:27 AM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    r1 and r2 should be R1 and R2, surely.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Thanks for that, everyone. I looked at it hundred times and didn't see the r1 and
    r2.

    I only gave the output a int value because that is what the design said to do. I also thought that since i had given it a float value that it should stay that way.

    I still can't get it to compile though. It refers to an 'expected expression before )', in the error message when I compile it, but i still haven't worked out how to use the error messages to locate the problem.

    Regards, phoenixg

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by phoenixg View Post
    Thanks for that, everyone. I looked at it hundred times and didn't see the r1 and
    r2.

    I only gave the output a int value because that is what the design said to do. I also thought that since i had given it a float value that it should stay that way.

    I still can't get it to compile though. It refers to an 'expected expression before )', in the error message when I compile it, but i still haven't worked out how to use the error messages to locate the problem.

    Regards, phoenixg
    Code:
     
    #include <stdio.h>		  	  	  	  			/*printf, scanf definitions*/
    #include <math.h>
    
    
    #define Vc 3.3 
    #define	Ve 0.75	  	 	 	  	  	  	  	  /* definition of the constants */
    #define Vin 0.02
    #define Hfe 95
    
    int main(void)
    {
    
    	float Ic,Vcc;								/*declared variables*/
    	float R1, R2, R3, R4;
    	float Ib, Vb, Ks, Vout;
                                                        V---- Missing comment prefix
    	printf("Enter the value of Ic:");	/*	prompts for the variables from the user*/
    	scanf("%f", &Ic);	   	   	   	   	   		/*inputs the variable as a float*/
    	
    	printf("Enter the value of Vcc:");
    	scanf("%f", &Vcc);
    	
    	printf("===================");
    	
      	Ib = Ic / Hfe;	   	   	   	   	      	    /*calculates the base current*/
    	R1 = (Vcc - Vc) / Ic;	    				/*calculates the value of R1*/
    	R2 = Ve / (Ic + Ib);						/*calculates the value of R2*/
    	Vb = Ve + 0.7;	    						/*calculates the value of Vb*/
    	R4 = Vb / (5 * Ib);	    					/*calculates the value of R4*/
    	R3 = (Vcc - Vb) / (6 * Ib);	      	  	    /*calculates the value of R3*/	 
    	Ks = r1 / r2;	  	  	  	  	  	  	    /*calculates the signal amplification*/
    	Vout = Vin * Ks; 	  	  	  	  	  	    /*calculates the output signal*/
    	
    	printf("Resistors:\n");
    	printf("R1 = %10d ohm\n", R1); 
    	printf("R2 = %10d ohm\n", R2);
    	printf("R3 = %10d ohm\n", R3);
    	printf("R4 = %10d ohm\n\n", R4);
    	
    	printf("Output voltage:\n",);
    	printf("Vout = %10.2f v \n", Vout);
    
    	printf("====================");
    	
    	return (0);
    }

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Hi,

    I was just wondering how I put the code in my message. When I have tried to copy it over it just copies the text and not a screen shot like with yours.

    Thanks

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's a note about using code tags at the top of the forum.

    [code] ...your code in here... [/code]


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    76
    printf("Output voltage:\n",);


    Get rid of this comma and you should be good to go.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 11:13 PM
  2. Writing a program to make a calendar
    By Northstar in forum C Programming
    Replies: 17
    Last Post: 11-07-2007, 11:34 AM
  3. writing a calendar program help please!!!
    By Newbie2006 in forum C Programming
    Replies: 7
    Last Post: 11-20-2002, 07:36 PM
  4. Help with a file writing program
    By pritesh in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 01:56 AM