C# question - switch statement with parameters :)?
sorry, Never mind. Alan helped me get it figured out:)
Thank You :) , Heather
Thank You :) , Heather
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Oct 27, 2008, 6:12 PM
Unless you've been given a 'template' to work to, I'd just do something like this:
/* PRE-CONDITION
The parameter pNum represents the product number. Any int value can be passed whether it's a valid product number or not.
*/
/* POST-CONDITION
The return value of the method represents the price corresponding to pNum. If pNum is not a valid product number, a price of zero is returned.
*/
All you're trying to do here is to document the method so that a developer calling it knows what needs to go in and what will come out.
heather lindsayPosted Oct 27, 2008, 6:56 PM
Thanks for everything Alan. :) finally got everything to work :)
ty ty, :) Heather
heather lindsayPosted Oct 27, 2008, 6:00 PM
Thank you for helping me Alan :)
I'm still a little confused as to what I should put as a post and pre condition though:( for my methods.if you have time, is there any way you could show me an example or something in my code like what its supposed to say. I'm just so confused about exactly what I should put.
:), Heather
AlanPosted Oct 27, 2008, 5:41 PM
Yes, as far as C# is concerned, it just means adding comments before the method's code.
The pre-condition needs to describe the parameter which is passed to the method and its allowable values.
The post-condition should describe the value to be returned by the method.
Also don't forget this part of the instructions:
"Stop the loop with the sentinel value -5 for the product number. Display each price using currency formatting."
Currently, you're using a sentinel of -1 and are displaying the price as a number without a currency symbol.
heather lindsayPosted Oct 27, 2008, 4:45 PM
Oops lol i didnt realize I had left out my "using system; " . Thank you for pointing that out :)
I was also wondering what it means to add pre and post conditions for the method? does this just mean add comments or something else completely?
Thanks again, Heather
AlanPosted Oct 27, 2008, 4:40 PM
All you seem to be missing is this using directive at the top of your program:
using System;
The program works fine when this is added.
heather lindsayPosted Oct 27, 2008, 3:53 PM
got it now:) ty