Thread: Error Help

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    8

    Error Help

    Hello all

    I am once again struggling with my homework. Any help is greatly appreciated. I don't know what the below errors mean. I will post the code if that helps.

    c:\documents and settings\litchfield\my documents\visual studio 2005\projects\homework_3\homework_3\homework_3.cpp (40) : error C2144: syntax error : 'int' should be preceded by ')'
    c:\documents and settings\litchfield\my documents\visual studio 2005\projects\homework_3\homework_3\homework_3.cpp (40) : error C2660: 'getTotalKWH' : function does not take 0 arguments
    c:\documents and settings\litchfield\my documents\visual studio 2005\projects\homework_3\homework_3\homework_3.cpp (40) : error C2059: syntax error : ')'
    Build log was saved at "file://c:\Documents and Settings\Litchfield\My Documents\Visual Studio 2005\Projects\Homework_3\Homework_3\Debug\BuildLog .htm"
    Homework_3 - 3 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Code:
    #include<stdio.h>
    
    #define low 5.151
    #define medium 7.110
    #define high 9.800
    
    int getUserInput ( );
    int getTotalKWH (int end_mtr, int start_mtr);
    
    int main ( )       
    {
    		int cust_num = 0;
    		int start_mtr = 0;
    		int end_mtr = 0;
    		int hours = 0;
    
    		printf ("This program will compute BetterJoules Electric Company Customer Bills");
    
    		printf ("\n\nPlease enter Customer Number: ");
    		
    			cust_num = getUserInput ( );
    
    		printf ("\n\nPlease enter starting meter reading:  ");
    		
    			start_mtr = getUserInput ( );
    
    		printf ("\n\nPlease enter ending meter reading:  ");
    		
    			end_mtr = getUserInput ( );
    
    		printf("\n\nTotal Kilowatt Hours used: ");
    
    			hours = getTotalKWH (int end_mtr, int start_mtr); 
    
    
    }
    
    int getUserInput ( )
    {
    		int input = 0;
    
    		scanf ("%d%*c", &input);
    
    		return input;
    
    }
    
    int getTotalKWH (int end_mtr, int start_mtr)
    {
    		int hours = 0;
    
    		hours = (end_mtr - start_mtr);
    
    		scanf ("%d%*c", hours);
    
    		return hours;
    
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    hours = getTotalKWH (int end_mtr, int start_mtr);
    If the stuff in red meant anything at all (which it doesn't), it would declare new variables end_mtr and start_mtr hiding the original variables of those names.

    Of course, since the stuff in red doesn't mean anything at all, it should be deleted.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > homework_3.cpp
    If you're programming in C, then rename the source to be homework_3.c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    10
    And you're main function should end with:

    Code:
    return(0);

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    8
    Thanks everyone. I appreciate the help. I will now spend hours working on the next small portion of the assignment

Popular pages Recent additions subscribe to a feed