Hi, I'm a complete beginner to coding, I'm studying Comp. Sci. at Bristol Uni in the Uk and am into my second week. The first thing we did was easy, the ol' printf "Hello World!" code, but we're onto our second coursework and I think I must have just missed something basic... I'm not looking for someone to write the code I need or anything like that, I'm not looking for coursework answers... It's simply that there must be some simple code I've just over looked... (ps the program is supposed to not utilise any "variable" at all, only functions)
Ok, the question boils down to giving you a set of data for the cost of printing different kinds of books. The data, costs of pages, etc is on the page which I'll post at the end. Anyway the work boils down to 4 parts:
Write a function that calculates the price of a job given the number of pages, price per page, price per plate, and number of copies.
Ok this was ok (I think...). Considering 4 possible variables: Cost of Plates, Cost of Paper, Number of Pages and Number of books, as well as binding the books and VAT, etc I've managed to get:
Code:
double book( double a, double b, double c, double d ) {
return (((b * c) + ((b/2) * d * a) + (200 * d)) * (117.5/100))/100 ;
}
And that seems to work fine. I plugged in the example data and tested it against the result they showed and it works. This is all fine and dandy.
# Write a function that calculates the price of a job given the number of pages and the number of copies for black and white printing. This function should call the function that you wrote for part 1.
# Write a function that calculates the price of a job given the number of pages and the number of copies for colour printing. This function should call the function that you wrote for part 1.
Ok, part 2... now this is where it starts to get slightly confusing... the only other code I know really is the printf one, so I wrote this:
Code:
int main ( void ) {
printf(" Black and White copy= %f\n", book(1,b,700,d) ) ;
printf(" Colour copy= %f\n", book(4,b,2800,d) ) ;
return 0 ;
}
And that prints fine. But I can't help feel this isn't really what I'm after... especially considering the next (and final) part of the excercise:
Write a main program that calculates the total price of printing 1000 colour books with 32 pages, 2000 black/white books with 40 pages and 400 black/white books with 160 pages. The main function should call the functions that you wrote for parts 2 and 3.
Now... this I got stuck on when I started it on mondy and lead to me putting this off all week untill today (surprise surprise deadline time >.>;; ), although I have also had a silly italian teacher going confusing me... but I digress. My first on this question was "how the heck do I do that?!".
I looked back through all the lecture slides... the first set were on the course outline, the double function I posted above and the main printf one. Nothing else. The second set are all about inputs and variables which this excercise doesn't use... So I had a search for some C guides online (sadly the course book we use is out of print and my copy is on order from the US and wont be here for a good few days -.-*) eventually I found something that I thought would help, another University course guide... all about "int"s and such... so I had a read through and thought maybe I could use the %f thing to refer to the double function above to calculate the three prices ofr the books... and basically... this is where I am now... I don't know how to "call" that first function without printing any text (the method I tried (and that is posted below) doesn't work). That's what I need to do, after that I need to print the total of the three results in one line. This is where I'm at now: (this code doesn't actually work sadly ;-; )
Code:
double book( double a, double b, double c, double d ) {
return (((b * c) + ((b/2) * d * a) + (200 * d)) * (117.5/100))/100 ;
}
int x ;
x=%f, book(4,32,2800,1000) ;
int y ;
y=%f, book(1,40,700,2000) ;
int z ;
z=%f, book(1,160,700,400) ;
double total( double p, double q, double r ) {
return p + q + r ;
}
int main ( void ) {
printf(" The total cost of this printing job is %f pounds./n", total(x,y,z) ) ;
return 0 ;
}
The actual page with all the data and instructions on it is here for refference:
http://www.cs.bris.ac.uk/Teaching/Re...sework/02.html
And I would like to stress again I am NOT looking for someone to do my coursework, I do not want this to be taken as lazy student trying to cheat through his course. I really just think I have missed something basic... That's what I want to find out, how can I calculate three different book prices, calling to the first formula, and then later print the total of the three prices togeather without using any inputs or variables.
If you can offer any help, thank you very much, if not, I'll be crying in a corner...
-Rich.