Thread: need help proofing a simple program

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    10

    Post need help proofing a simple program

    i'm new to C, and i need someone to help me proof my first program.

    the compiler points me to the problematic line, but i can't for the life of me see the problem.

    can i send the .c file to anyone to fix ?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    How about just the compiler error message and the code segment that produces the error.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    10
    it seems fine to me...
    it's probably something stupid.
    syntactic maybe.
    but i can't find it...

    the program's supposed to accept a float and round it up or down depending on the float.
    it's also supposed to determin whether the float is a true decimal fraction or just something like 4.0

    here's the code

    Code:
    #include <stdio.h>
    
    int output, run=1, frac_mod, reduce( float input);
    float input, decimal;
    
    main()
    {
    	while(run=1)
    	{	
    		printf("input a decimal fraction:\n");
    		scanf("%f",input);
    		
    		frac_mod=reduce ( float input);
    		
    		switch(frac_mod) //this is where the actual rounding is done by assigning a float into an int
    		{
    			case 2:
    			{
    				output=input+1;
    				printf("\n%f is rounded up to %d\n",input, output);
    				break;
    			}
    			case 1:
    			{
    				output=input;
    				printf("\n%f is rounded down to %d\n",input, output);
    				break;
    			}
    			default:
    			{
    				printf("\n%d is not a decimal fraction...\n\njackass\n",input);
    				break;
    			}
    		}
    	}
    }
    
    int reduce( float input) // determines which way to round, and whether input is a true fraction
    {
    	decimal=input;
    	
    	while(decimal>1)
    	{
    		if(decimal>100)
    		decimal=decimal-100;
    		else
    		{
    			if(decimal>10)
    			decimal=decimal-10;
    			else
    			decimal=decimal-1;
    		}
    	}
    	if(decimal>=0.5)
    	return 2;
    	else
    	{
    		if(decimal!=0)
    		return 1;
    		else
    		return 0;
    	}
    }
    the compiler says there's a "parse error before float" in line 13 of the code.
    where the function reduce is first called.

    do you see a problem ?

    also, if you see any other problem in the program please let me know...
    as i understand it a code can compile perfectly and still not a working exe make...

    so any input is appreciated.
    Last edited by SymDePro; 05-06-2009 at 03:32 PM.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quick look tells me you should have an ampersand:
    scanf("%f",&input);

    Next, get rid of the 'cast' or whatever it is when calling your function reduce:
    frac_mod=reduce ( input);

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    10
    working now...
    thanx a bunch

Popular pages Recent additions subscribe to a feed

Similar Threads

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