My preferred solution:
#include<iostream>
using namespace std;
int ReadInputFlava ();
int ReadInputCart ();
int main()
{
int flava,cart,delivery;
flava = 0;
cart = 0;
cout<<" Mulaudzi Ice-Cream Limited\n"
<<" --------------------------\n";
flava = ReadInputFlava();
cart = ReadInputCart();
cout<<"Ur flava is : "<<flava<<endl;
cout<<"Ur # of cartoons is : "<<cart<<endl;
return 0;
}
int ReadInputFlava ()
{
int a;
cout<<"Please enter flavour(1=choco,2=caramel,3=mint) : ";
cin>>a;
return a;
}
int ReadInputCart ()
{
int b;
cout<<"Please enter number of cartoons(1-20) : ";
cin>>b;
return b;
}
This makes the program a little more modular. And I prefer not to pass values via the parameter list unless it can't be avoided. Personal choice.
WaltP
Posting Sage w/ dash of thyme
10,492 posts since May 2006
Reputation Points: 3,348
Solved Threads: 943
This makes the program a little more modular.
Well forgive me for butting in, but here modularity is not an issue since he is not building a Library module but a small program.
As far as writing normal programs are concerned the coder should always be concerned with the best and the fast implementataion wrt to both memory requirements and speed.
But still this is just me, I thought just wanted to let you know.
Any constructive criticisms appreciated.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Maintainability and readability are generally the 2 most important goals for any coder to aspire to (usually far more important than optimum speed & memory usage), its a good habit to get into.
Actully that is not true in all the cases.
For places or applications where the performance is of peak importance, optimum speed and memory do make a large amount of difference.
I dont mean that modularty is not important or you should go for speed more than modularity, just that it depends on the area of application in which the program is used.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
speed is sometimes much more important than modularity or maintainability. I worked several years on a program that had to get data real-time from barcode readers on packages as the packages moved along an assembly line. Then the program had to look-up data in a database whose key was the barcode, format the data, and send it to a large-character printer that would print information on the side of the packages when they moved past the printer. All that had to be done in less than 1/2 second and management thought that was too slow. We even resorted to assembly language to squeeze out every millisecond we could.
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
speed is sometimes much more important than modularity or maintainability. I worked several years on a program that had to get data real-time from barcode readers on packages as the packages moved along an assembly line. Then the program had to look-up data in a database whose key was the barcode, format the data, and send it to a large-character printer that would print information on the side of the packages when they moved past the printer. All that had to be done in less than 1/2 second and management thought that was too slow. We even resorted to assembly language to squeeze out every millisecond we could.
Thats exactly the point i was trying to put forward, but as i belong to the new generation couldnt find a real world example. Thanks, this was the kind of example i was looking for.
*but in the end these ppl will say that nowadays as the computing speed and memory has increased the optimizations dont matter. Well in this case the argument continues...*
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
>> there are no "always do" or "never do" rules
Never ever use gets():mrgreen:
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
name even one case where the programmer has control over gets(). The standards committee probably left it in because taking it out might break a lot of programs that already use it. The statement you quoted is just a bunch of frabridated bull****.
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
Maybe it's bull**** but as long as it is in the standards I can't deny it.
... and neither do you use it. ;)
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733