DarkendSinz30 3 years ago Anyone good at programming logic?

1. DarkendSinz30

hey I need some help if you can

2. infinity_

ok.. just show me the assignment..

3. DarkendSinz30

start read Customer_Name perform Calculate_SafetyLevel() perform Evaluate_History() print Customer_Name print 'Credit History of' Client_Name 'is' History print 'Safety Level of' Client_Name 'is' Safety_Level stop Calculate_SafetyLevel() read Customer_Income if Customer_Income >= \$5000 Safety_Level = Excellent elseif Customer_Income >= \$3000 Safety_Level = Good elseif Customer_Income >= \$1500 Safety_Level = Ok endif return Evaluate_History() read Customer_History if Customer_History = Clean History = Good elseif Customer_History = Pending_Balance History = OK elseif Customer_History = Defaulted History = Risky endif return I need to optimize the above pseudocode to make it more efficient.

4. infinity_

ehm.. what do you mean more efficient? The code looks optimal for what you want it to do.. Perhaps the one thing you could do is to store the income and the history, so that you can recall them in constant time, instead of the O(something) it would normally take.It's good though to give a description of each procedure, because if (for example) the history and encome is read in constant time, the above "correction" instead of making your code better, would make it use more memory than needed.

5. DarkendSinz30

okay but how does this make things more efficient for the program? will it allow the process to continue?

6. kTwitch

Depending on the language, turning the if-else structures into switch structures may make the code slightly more efficient.

7. infinity_

More efficient means, either that your program runs in less time than it used to, or your program uses less memory than it used to.With my optimization, you just don't need to ask for a users history, or income if you have already stored it.That's why your program runs faster than it used to but uses some more memory in order to store history-income in an array.

8. DarkendSinz30

Okay @kTwitch define switch structures a little bit?

9. DarkendSinz30

@infinity that works so if I just replace the() beside history with a store function it should make it more efficient for the program?

10. kTwitch

Depends on language again, but it's generally in the format - switch (variable) case value: code; break; case value: code; break; etc. There's also sometimes a default case at the bottom. However, you can only use it if the if-else statements aren't reliant on the previous one being false, if that makes sense.

11. DarkendSinz30

okay but how would that work for this program for instance?

12. infinity_

@DarkendSinz30 I am just saying that storing stuff in memory could make your program run faster.In my opinion though, the assignment is quite abstract, by saying "make the code more efficient" you could mean anything, you can't possibly know what exactly to correct :P

13. DarkendSinz30

so wait if I replace the else if with a switch program it would run as if it were switching everything and putting it in a proper order?

14. kTwitch

switch (Customer_History) case Clean: History = Good; etc. I agree with @infinity_ though in that the assignment is a bit vague.

15. DarkendSinz30

I am sorry I am lost a little because this is the first time I am taking programming.

16. kTwitch

17. DarkendSinz30

I understand it is vague yes but if I do the switch structure to it that could make it more easier to read right?

18. DarkendSinz30

@infinity_ so in this program where would the store go if I was to place it?

19. infinity_

i mean something like that: read customers history; if(array[history]!=EMPTY) return history.status; else ..... array[history]=customer.history.. or something like that, keep an array of the history so that you can leave the function right away, without keep calculating the same things over and over

20. DarkendSinz30

okay now I am beginning to understand it

21. DarkendSinz30

Thank you guys for the help it was greatly appericated

22. Kevin0528

Im still n confussed

23. infinity_

more details..