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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Oct 27, 2008, 2:12 PM EDT
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 lindsay17 reputationPosted Oct 27, 2008, 11:53 AM EDT
got it now:) ty
AlanRank #669 · 3.6K reputationPosted Oct 27, 2008, 12:40 PM EDT
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 lindsay17 reputationPosted Oct 27, 2008, 12:45 PM EDT
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
AlanRank #669 · 3.6K reputationPosted Oct 27, 2008, 1:41 PM EDT
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 lindsay17 reputationPosted Oct 27, 2008, 2:00 PM EDT
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
heather lindsay17 reputationPosted Oct 27, 2008, 2:56 PM EDT
Thanks for everything Alan. :) finally got everything to work :)
ty ty, :) Heather