-
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
-
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.
-
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
-
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);
-
ahh ok :)....thanks a lot for your help