Newbie

This is a discussion on Newbie within the C Programming forums, part of the General Programming Boards category; Hey guys I have this program that doesn't compile Code: #include <stdio.h> typedef struct{ double price; double tax; }Book; double ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    77

    Newbie

    Hey guys I have this program that doesn't compile

    Code:
    #include <stdio.h>
    typedef
    struct{
            double price;
            double tax;
            }Book;
    double findTotal(Book cartoon);
    
    void main(void)
    {
      Book comics = {0.0, 0.0};
      double total = 0.0;
    
    readdata(comics.price, comics.tax);
    total= findTotal(comics);
    puts(total);
    }
    
    double findTotal(Book cartoon)
    {
    
    double total;
      total= cartoon.price+cartoon.tax;
    return total;
    This is the error it gives:

    Code:
    test2.c: In function `main':
    test2.c:16: incompatible type for argument 1 of `puts'
    test2.c:10: warning: return type of `main' is not `int'
    Is their a way to keep the main void still return the value of total to it?
    And why is it giving me error for puts?

    thanks for any help

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    26
    Ouch, never ever ever ever void main. Here's my version of the code of what I think you're trying to do. You never posted a readata() function so I'm assuming it's there somewhere. I took it out due to simplicity. Here we go:

    Code:
    #include <stdio.h>
    
    /* book structure */
    struct book{
    	double price;
    	double tax;
    };
    
    /* Function prototype */
    double findTotal(struct book cartoon);
    
    /* main func */
    int main(){
    	struct book comic = {10.0, 5.0};
    	double total = 0.0;
    	
    	total = findTotal(comic);
    	
    	printf("Total = $%.2f\n", total);
    	
    	return 0;
    }
    
    /* Find the total */
    double findTotal(struct book cartoon){
    	double total;
    
    	total = cartoon.price + cartoon.tax;
    
    	return total;
    }
    EDIT: I added values other than 0.0 when intializing comic so you could see a real total.
    Last edited by Pressure; 04-19-2005 at 12:07 AM.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    77
    thanks .

    And one more question what does the statement "Use interactive appraoch to read two doubles values into the 2 data members price and tax of struct Book type variable named comics from the keyboard?.

    So the main question is what is interactive approach?

    THanks

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    26
    It probably means it just wants you to ask the user for input from the keyboard. The code for that would look something like:

    Code:
    printf("Enter the price: ");
    scanf("%f", &comic.price);
    
    printf("Enter the amount of tax: ");
    scanf("%f", &comic.tax);

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    77
    ahh ok ....thanks a lot for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 07:46 AM
  2. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  3. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 08:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 03:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21