473,388 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

passing variables w/o making them global

I'm an extreme newbie at C++ and am working on my final project for my beginner course. I have an issue, though, and I'm hoping I can get a nudge in the right direction.

The program functions via a user menu:

void menu(void)

and looks like this:
E - Enter number of trades by day................// int getTrades(void)
V - View previously entered data...................// void viewTrades(trades)
S - View a statistical summary of the data....// void statSummary(trades)
X - Exit the program

(trades[5] is the array stored in getTrades)

I'm using a switch for the menu. Since viewTrades and statSummary use data entered by the E option, how do I pass the values of the array elements to those functions without passing them to menu()? That just makes a mess.

Sorry if these are dumb questions, but I'm pretty lost here. Thanks very much in advance.
Dec 17 '07 #1
6 1392
gpraghuram
1,275 Expert 1GB
I'm an extreme newbie at C++ and am working on my final project for my beginner course. I have an issue, though, and I'm hoping I can get a nudge in the right direction.

The program functions via a user menu:

void menu(void)

and looks like this:
E - Enter number of trades by day................// int getTrades(void)
V - View previously entered data...................// void viewTrades(trades)
S - View a statistical summary of the data....// void statSummary(trades)
X - Exit the program

(trades[5] is the array stored in getTrades)

I'm using a switch for the menu. Since viewTrades and statSummary use data entered by the E option, how do I pass the values of the array elements to those functions without passing them to menu()? That just makes a mess.

Sorry if these are dumb questions, but I'm pretty lost here. Thanks very much in advance.

Have you heard about classes in c++?
Start reading about classes and you will get an idea on how to to use it to solve your problem.

Thanks
Raghuram
Dec 17 '07 #2
Thanks for your response. We just barely touched on classes in the last class, but we're not supposed to use/need them for this project. Any other ideas?

Have you heard about classes in c++?
Start reading about classes and you will get an idea on how to to use it to solve your problem.

Thanks
Raghuram
Dec 17 '07 #3
gpraghuram
1,275 Expert 1GB
Thanks for your response. We just barely touched on classes in the last class, but we're not supposed to use/need them for this project. Any other ideas?

If u shuldnt use classes then you shuld pass the values as arguments.
Do you have good knowledge in C? then it is very easy for you.

Thanks
Raghuram
Dec 17 '07 #4
Studlyami
464 Expert 256MB
you could also call the menu function which will return a char to your main (or any other function for that matter). From your main you then can do a switch statement based on the results returned from menu.
Dec 17 '07 #5
Thanks. I ended up handing it in without getting it to work completely, and asked my teacher if he'd mind explaining to me how to make it work right at some point. I'm not worried about my grade, so much, but next semester I'm taking an intro to Java class and I'll need to understand this stuff by then!
Dec 20 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
You mean you can't:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. Trades trades[5];
  4. int choice;
  5.      choice = GetMenuChoice();
  6.      if (choice == 'V')
  7.      {
  8.           ViewTrades(trades);
  9.      }
  10. etc...
  11. }
  12.  
??
Dec 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: gabor | last post by:
hi, as far as i know in python there aren't any private (i mean not accessible from the outside of the object) methods/fields. why? in java/c++ i can make a method private, this way...
12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
3
by: jeffg | last post by:
The answer probably is staring me in the face and I don't see it, so I'll just ask. I try to limit the scope of variables and avoid global variables. But sometimes I get stumped by the following...
13
by: Sunil | last post by:
Hi all, I want to know how good or bad it is using global variables i.e advantages and disadvantages of using global variables. Sunil.
25
by: Daniel Bass | last post by:
how do i declare a global variable in c#.net? it's like it want's everything in classes... there are times when globals are good, like having constants in a program which apply to several...
17
by: Woody Splawn | last post by:
I am finding that time after time I have instances where I need to access information in a variable that is public. At the same time, the books I read say that one should not use public variables...
7
by: jab3 | last post by:
Does JavaScript have "static" variables. That is, as in C (or local in Perl)? How can I keep a variable in a JavaScript function that doesn't change from call to call? It may not make sense in...
1
by: johnjsforum | last post by:
Buddies, I have a web page to create HTML buttons dynamically as in the “formDivColorPicker” function ////////////////////////////////////////////////////////////////////////////////////...
4
by: icarus | last post by:
global_vars.py has the global variables set_var.py changes one of the values on the global variables (don't close it or terminate) get_var.py retrieves the recently value changed (triggered right...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.