| | |
local variables
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hi,
below is my unfinished code.what i realy want help on is how do i display or take the values of a and b to main?
below is my unfinished code.what i realy want help on is how do i display or take the values of a and b to main?
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int ReadInput (int,int); float CalcIceCreamCost (); float CalcDeliveryCost (); float DisplayCosts (); int main() { int flava,cart,delivery; flava = 0; cart = 0; cout<<" Mulaudzi Ice-Cream Limited\n" <<" --------------------------\n"; ReadInput(flava,cart); cout<<"Ur flava is : "<<flava<<endl; cout<<"Ur # of cartoons is : "<<cart<<endl; return 0; } int ReadInput (int a,int b) { cout<<"Please enter flavour(1=choco,2=caramel,3=mint) : "; cin>>a; cout<<"Please enter number of cartoons(1-20) : "; cin>>b; return a,b; }
[i]What makes the world to be a dangerous place is not the people who do evil,but is the people who just sit on their buds. :)
You can't return multiple values from a function, you probably want to pass your variables by reference instead. ie
Notice the ampersands (highlighted in red), to denote 'pass by reference' ... also, the function has no retun statement, since it is modifying variables elsewhere in the prgram and not returning a value, hence the function's return type is now void
void ReadInput (int& a,int& b) { cout<<"Please enter flavour(1=choco,2=caramel,3=mint) : "; cin>>a; cout<<"Please enter number of cartoons(1-20) : "; cin>>b; }
Notice the ampersands (highlighted in red), to denote 'pass by reference' ... also, the function has no retun statement, since it is modifying variables elsewhere in the prgram and not returning a value, hence the function's return type is now void
Last edited by Bench; Aug 12th, 2006 at 7:49 am.
¿umop apisdn upside down? My preferred solution:
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.
C++ Syntax (Toggle Plain Text)
#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; }
•
•
•
•
Originally Posted by WaltP
This makes the program a little more modular.
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.
I don't accept change; I don't deserve to live.
•
•
•
•
Originally Posted by ~s.o.s~
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.
¿umop apisdn upside down? •
•
•
•
Originally Posted by Bench
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.
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.
I don't accept change; I don't deserve to live.
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.
•
•
•
•
Originally Posted by Ancient Dragon
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.
*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...*
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- ASP Code Works on Local 127.0.0.1 but Not on ISP's Server (ASP)
- [Warning] address of local variable returned??? (C++)
- Function variables (PHP)
- Object-Oriented Programming (C++)
- program help (C++)
- Function that returns void (C++)
- Pounds to Grams Conversion (C++)
- Data Abstraction (Computer Science)
- Locality (C)
Other Threads in the C++ Forum
- Previous Thread: find the vector with the most elements
- Next Thread: Search a txt file for words
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






