• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Vostro

Member
I think I found a solution that I didn't even think about. I'll just implement an on screen keyboard using jquery instead of bringing up the android keyboard.
 
Really digging the changes in Swift 1.2. Wish there were more OSX tutorials, though, most everything seems focused on iOS.

To date, the best books I've found for getting your feet wet in Mac OS X are the Big Nerd Ranch books. They're not written in Swift, but frankly most of the difficulty lies in learning the Objective-C AppKit frameworks. And they're not nearly as clean or beginner friendly as their UIKit counterparts in iOS, several parts still date back to the OpenStep days.

Cocoa Programming for Mac OS X
Advanced Mac OS X Programming

There's not nearly as much demand for OS X development as there is for iOS development, so I expect lessons in Swift will take some time to find their footing in OS X. Plus, some of the most powerful, interesting and portable(!) OS X frameworks and functions tend to be C based, so having some footing in C and UNIX makes sense in the long run. Especially if you ever want to give Linux or app programming for other UNIX kernels a try someday.

For clean, modern Objective-C, I highly recommend the Scott Meyers endorsed Effective Objective-C 2.0. It should help bridge some gaps between Objective-C and Swift, and it'll let you know what parts of Objective-C you don't need anymore.

The Objective-C 2.0 Phrasebook is another one that I've enjoyed having by my side. Lots of quick, recipe solutions there that work for AppKit (OS X) and UIKit (iOS), and the examples are short enough that they aren't hard to translate to Swift. It's also written by the author behind the GNUstep Objective-C runtime, so he knows his stuff.
 
To date, the best books I've found for getting your feet wet in Mac OS X are the Big Nerd Ranch books. They're not written in Swift, but frankly most of the difficulty lies in learning the Objective-C AppKit frameworks. And they're not nearly as clean or beginner friendly as their UIKit counterparts in iOS, several parts still date back to the OpenStep days.

Cocoa Programming for Mac OS X
Advanced Mac OS X Programming

There's not nearly as much demand for OS X development as there is for iOS development, so I expect lessons in Swift will take some time to find their footing in OS X. Plus, some of the most powerful, interesting and portable(!) OS X frameworks and functions tend to be C based, so having some footing in C and UNIX makes sense in the long run. Especially if you ever want to give Linux or app programming for other UNIX kernels a try someday.

For clean, modern Objective-C, I highly recommend the Scott Meyers endorsed Effective Objective-C 2.0. It should help bridge some gaps between Objective-C and Swift, and it'll let you know what parts of Objective-C you don't need anymore.

The Objective-C 2.0 Phrasebook is another one that I've enjoyed having by my side. Lots of quick, recipe solutions there that work for AppKit (OS X) and UIKit (iOS), and the examples are short enough that they aren't hard to translate to Swift. It's also written by the author behind the GNUstep Objective-C runtime, so he knows his stuff.

Nice! I write Obj-C a decent amount for work (and my next job might be even moreso) so these are good links for me. Thanks!
 
Is it normal to be comfortable in C and struggling in C++? Even ignoring features like templates, it always takes me 2x-3x longer to finish something in C++ for all the debugging I do.
 

XenodudeX

Junior Member
So I need help.

I'm making a Diner Menu Tool in Visual Studios, and the part I have left is adding the prices + tax and printing them on a listbox. It's suppose to look like this:

Capturer.jpg


The instructions say I have to use ANSI, but I have no idea what that is or how it works. I have to line up the values of the total, sub total, the food prices and tax.
 

tokkun

Member
Is it normal to be comfortable in C and struggling in C++? Even ignoring features like templates, it always takes me 2x-3x longer to finish something in C++ for all the debugging I do.

That seems a little strange. C++ is like 99.9% a superset of C, so most people going from C->C++ will just write C-compatible programs and slowly add in C++ features where it makes things more convenient. What exactly are you doing differently that is tripping you up?
 
That seems a little strange. C++ is like 99.9% a superset of C, so most people going from C->C++ will just write C-compatible programs and slowly add in C++ features where it makes things more convenient. What exactly are you doing differently that is tripping you up?

Yea, but most people learning c++ also try to force OOP into every little detail about their program. I mean it's part of the normal learning experience, so I wouldn't worry too much. Definitely normal though.
 
That seems a little strange. C++ is like 99.9% a superset of C, so most people going from C->C++ will just write C-compatible programs and slowly add in C++ features where it makes things more convenient. What exactly are you doing differently that is tripping you up?

To what cpp_is_king said, initially it was trying to build objects then writing programs, but that's not intuitive at all. Now I try to write programs in a more procedural fashion and add or build up classes as needed, but I end up debugging stupid things like needing a const vector<bool>& instead of a const vector<bool>. For all the features it adds, it feels like the language is far too verbose for its own good and I end up thinking about a lot of things that don't contribute to my program's end goal.
 

tokkun

Member
To what cpp_is_king said, initially it was trying to build objects then writing programs, but that's not intuitive at all. Now I try to write programs in a more procedural fashion and add or build up classes as needed, but I end up debugging stupid things like needing a const vector<bool>& instead of a const vector<bool>. For all the features it adds, it feels like the language is far too verbose for its own good and I end up thinking about a lot of things that don't contribute to my program's end goal.

So why do you want to use C++?

In large part, the people who have to use C++ are those who need low-level control of program performance, and for whom choosing between passing by reference vs passing by value may be important.

If that's not you, you may want to consider Java instead, as it was invented to address those issues in C++, including the specific problem you mentioned.
 
So why do you want to use C++?

In large part, the people who have to use C++ are those who need low-level control of program performance, and for whom choosing between passing by reference vs passing by value may be important.

If that's not you, you may want to consider Java instead, as it was invented to address those issues in C++, including the specific problem you mentioned.
(1) Because my school requires it right now
(2) I love systems programming

Like I said, I like C. It's easy to understand but powerful and still used everywhere. C++ seems to be where things are headed though.
 

Two Words

Member
I'm having an issue with using dynamic multivariable arrays in C++. I'm using the new C++ 11 standard.

I have the code below as a function prototype. *oldSim is a dynamic multidimensional array that is created later in the program. When I compile, the compliler throws an error that columns isn't declared in the scope. Is there a method to doing a prototype of a multivariable dynamic array?

Code:
void firstGen(fstream &file, char *oldSim[][columns]);


Also, I seem to have an improper idea on how creating a dynamic multidimensional array works. Apparently I have to construct it with a for loop? If I do that, will I still be able to navigate through the pointer with pointer arithmetic? For example, will I be able to go down exactly one row in the array by adding the number of total columns exist in the array to the pointer?
 

NotBacon

Member
I'm having an issue with using dynamic multivariable arrays in C++. I'm using the new C++ 11 standard.

I have the code below as a function prototype. *oldSim is a dynamic multidimensional array that is created later in the program. When I compile, the compliler throws an error that columns isn't declared in the scope. Is there a method to doing a prototype of a multivariable dynamic array?

Code:
void firstGen(fstream &file, char *oldSim[][columns]);


Also, I seem to have an improper idea on how creating a dynamic multidimensional array works. Apparently I have to construct it with a for loop? If I do that, will I still be able to navigate through the pointer with pointer arithmetic? For example, will I be able to go down exactly one row in the array by adding the number of total columns exist in the array to the pointer?

Is columns a global? I think the preprocessor needs to know if you're going to use it in a function prototype. Try:

Code:
#define COLUMNS 5
... code...
void firstGen(fstream &file, char *oldSim[][COLUMNS]);
... code ...

If you're trying to pass the value columns when you call the function, you can't do that (at least this way). If you're using bracket '[]' syntax to declare a multidimensional array, all but the first dimension must be bounded with a value upon declaration.
 

Two Words

Member
Is columns a global? I think the preprocessor needs to know if you're going to use it in a function prototype. Try:

Code:
#define COLUMNS 5
... code...
void firstGen(fstream &file, char *oldSim[][COLUMNS]);
... code ...

If you're trying to pass the value columns when you call the function, you can't do that (at least this way). If you're using bracket '[]' syntax to declare a multidimensional array, all but the first dimension must be bounded with a value upon declaration.

I have to create a dynamic multivariable array that will be dependent on the variables rows and columns. The program will have to navigate through the array using pointer arithmetic, bracket notation isn't allowed, and manipulate the array according to a game's rules. I've got every aspect of this program down pretty well outside of actually constructing the multi-dimensional dynamic array. I think I understand how to properly navigate it using pointers, but now I'm concerned I'm doing this wrong if I cannot declare a 2D dynamic array like this.
 
To what cpp_is_king said, initially it was trying to build objects then writing programs, but that's not intuitive at all. Now I try to write programs in a more procedural fashion and add or build up classes as needed, but I end up debugging stupid things like needing a const vector<bool>& instead of a const vector<bool>. For all the features it adds, it feels like the language is far too verbose for its own good and I end up thinking about a lot of things that don't contribute to my program's end goal.

This is probably beside the point, but just another tooltip to add to your arsenal - never use a vector<bool> for anything. It never should have been added to the language and it will probably one day be removed. The reasons are highly technical and not worth getting into. You can use an std::bitset<N> if you know the number of bits you need at compile time, otherwise just use a vector<uint8_t> and implement the logic yourself. Some would tell you that there's a nice boost alternative, but I would tell you to not even go there. The tradeoffs aren't worth it.

A lot of the verbosity can be removed through the use of recent C++11 language features such as auto and range based for loops.

In any case, what you're going through is normal. It takes a while to get a feel for how to do C++ the right way.
 

tokkun

Member
I have to create a dynamic multivariable array that will be dependent on the variables rows and columns. The program will have to navigate through the array using pointer arithmetic, bracket notation isn't allowed, and manipulate the array according to a game's rules. I've got every aspect of this program down pretty well outside of actually constructing the multi-dimensional dynamic array. I think I understand how to properly navigate it using pointers, but now I'm concerned I'm doing this wrong if I cannot declare a 2D dynamic array like this.

Code:
void manipulate_2d_array(..., char* flat_2d_array, int num_rows, int num_cols);

void manipulate_2d_array(..., char** nonflat_2d_array, int num_rows, int num_cols);

which one you use depends on how you construct the array.
 

Nesotenso

Member
ok this is going to be a stupid question, but I always get confused over this point.

If someone is talking about 64 bit computing, does this mean that the physical address of each memory space is 64 bits? so if I print &A (of any variable A) i get a 64 bit value back?

second question is about the length of the actual contents of an address.
in x86 computing, is a byte the maximum amount a address space can hold or is the value in an address space also 64 bit long?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
64 bit means that the architecture has 64 bit registers as opposed to 32 bit ones.
 

Nesotenso

Member

so if I declare a char A in C, &A is 64 bit number and the value that register contains is 8 bits(because of type char) but it can hold up to 64 bits, right?

I guess my question is that if an integer is 4 bytes long, why does each register hold only one byte instead of more (if the max capacity of a register is 8 bytes)?
 
so if I declare a char A in C, &A is 64 bit number and the value that register contains is 8 bits(because of type char) but it can hold up to 64 bits, right?

I guess my question is that if an integer is 4 bytes long, why does each register hold only one byte instead of more (if the max capacity of a register is 8 bytes)?

When you use &A, the program is retrieving the memory address where that data resides, not the register address. In a 64-bit architecture that value will be a 64-bit (8 byte) address, but the number of address bits does not equal the number of allocated space for each piece of data.

Most CPU registers now are at least 32-bits long, so they're capable of holding a full int.
 

Nesotenso

Member
When you use &A, the program is retrieving the memory address where that data resides, not the register address. In a 64-bit architecture that value will be a 64-bit (8 byte) address, but the number of address bits does not equal the number of allocated space for each piece of data.

Most CPU registers now are at least 32-bits long, so they're capable of holding a full int.
thanks for the reply. two questions:

so CPU registers are different from your ordinary memory addresses?

but by design each memory address holds only a byte right, but CPU registers can hold more?

So in 64 bit architecture, registers are 64 bits, machine word size is 64 bits and memory address values are 64 bits ( with each memory address having 8 bits).
 
thanks for the reply. two questions:

so CPU registers are different from your ordinary memory addresses?

but by design each memory address holds only a byte right, but CPU registers can hold more?

So in 64 bit architecture, registers are 64 bits, machine word size is 64 bits and memory address values are 64 bits ( with each memory address having 8 bits).

1) Yes. Registers are accessed through CPU specific assembly commands as the registers are physically on the CPU. Data stored in memory has to be loaded into a register/cache.

2) Each address holds a bit and that bit is either a 0 or 1. To aid understanding, addresses are normally written in hexadecimal and incremented on a byte-by-byte basis since all data types are no smaller than one byte. CPU registers generally only hold one piece of data no matter the size, while memory holds however many pieces that will fit.

Again, register and word size is dependent on the implementation. A 64-bit CPU could easily have a 32-bit register and have a 32-bit word size. You would have to check the documentation supplied by the chip maker.
 

Nesotenso

Member
1) Yes. Registers are accessed through CPU specific assembly commands as the registers are physically on the CPU. Data stored in memory has to be loaded into a register/cache.

2) Each address holds a bit and that bit is either a 0 or 1. To aid understanding, addresses are normally written in hexadecimal and incremented on a byte-by-byte basis since all data types are no smaller than one byte. CPU registers generally only hold one piece of data no matter the size, while memory holds however many pieces that will fit.

Again, register and word size is dependent on the implementation. A 64-bit CPU could easily have a 32-bit register and have a 32-bit word size. You would have to check the documentation supplied by the chip maker.

for the bolded part, I thought it was the other way round. so memory holds only one byte ( at maximum)?


In the example you give I guess the datapath width is at least 64 bits?



Wikipedia has a nice write up on 64-bit architecture. It will probably answer a lot of your questions.
yup reading through that.
 
for the bolded part, I thought it was the other way round. so memory holds only one byte ( at maximum)?


In the example you give I guess the datapath width is at least 64 bits?




yup reading through that.
Read up on the register <-> cache <-> memory <-> secondary storage hierarchy. That should answer your questions, but if not feel free to post in here or PM.
 

Two Words

Member
Code:
void manipulate_2d_array(..., char* flat_2d_array, int num_rows, int num_cols);

void manipulate_2d_array(..., char** nonflat_2d_array, int num_rows, int num_cols);

which one you use depends on how you construct the array.

How do I create dynamic 2D arrays using the newer C++ standard?
 
ok this is going to be a stupid question, but I always get confused over this point.

If someone is talking about 64 bit computing, does this mean that the physical address of each memory space is 64 bits? so if I print &A (of any variable A) i get a 64 bit value back?

second question is about the length of the actual contents of an address.
in x86 computing, is a byte the maximum amount a address space can hold or is the value in an address space also 64 bit long?

In x86, registers are 32-bits. In x64, registers are 64-bits. This number is called the word size. A cpu only has a handful of registers, and an even smaller number that can be used for general purposes. For example, one register is the instruction pointer, called EIP on x86 and RIP on x64. This is an example of a special purpose register.

A computer generally accesses memory by means of cpu instructions that move values between registers and memory. To multiply two numbers in memory, it first might load them into registers for example. This is why x64 has a 64 bit address space. Because these instructions have to reference memory. And since the registers are 64-bit, it can reference an address that's 64 bits.

Things like chars, ints, etc are higher language level concepts. A char is 1 byte (8 bits) because that's what the C language says (If we want to be pedantic, it says that a char is at least bits, so in theory you can't rely on sizeof(char) == 1). How the compiler generates the code to make these operations possible is up to it. But it always does so through registers that are exactly the size of one word.

But a byte is always 8 bits, independent of architecture. That's just the definition of a byte.

for the bolded part, I thought it was the other way round. so memory holds only one byte ( at maximum)?
The smallest addressable unit of memory is 1 byte. Remember that every operation has to go through registers, and the registers are 64 bits or 32 bits depending on platform. But the registers are subdivided. On x86, EAX is 32 bits. But you can address the low 2 bytes of this register as ax. And you can address the high and low bytes of ax as ah and al, respectively. But you can't go smaller. So 1 byte is the smallest unit of memory you can load.
 

XenodudeX

Junior Member
I'm having a bit of trouble with my Visual Basic assignment. I basically have to make a program that adds and prints the subtotals for the meals selected, and also multiplies the sub total with a tax, and then also print the full total in a listbox as a receipt.
This is what it's suppose to look like:
Capturer.jpg


And this is the coding that I have right now. (Please excuse the messyness)

http://pastebin.com/embed_js.php?i=M9PqGFrg

know there has to be a way to write code that reads the selected meals and calculate the total price, but I'm not sure where to start.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Assuming that's a straight copy-paste from whatever text editor you're using, and that it's properly indented, you'll want to use
Code:
[\CODE] tags to preserve whitespace and make the typeface a monotype so it's easier to read.

No idea about the actual code.

Alternatively you could use [URL="http://pastebin.com/"]pastebin[/URL].
 
I'm having a bit of trouble with my Visual Basic assignment. I basically have to make a program that adds and prints the subtotals for the meals selected, and also multiplies the sub total with a tax, and then also print the full total in a listbox as a receipt.
This is what it's suppose to look like: [snip]

And this is the coding that I have right now. (Please excuse the messyness)

[more snips]

I know there has to be a way to write code that reads the selected meals and calculate the total price, but I'm not sure where to start.

It's a personal preference, but I recommend Pastebin for sharing code in public. They also have an option for syntax highlighting for many programming languages, including Visual Basic.

Codepad is a similar tool, though it also offers a means of running code through in interpreter. No VB support, unfortunately.

EDIT: What Haly said works great, too.

FAKE EDIT2: Though I am not a Visual Basic expert by any means, it would also help if you could show us your output right now. It's very hard to see, from the code alone, what it's supposed to do. Especially with the amount of repeated functionality in there.
 
In x86, registers are 32-bits. In x64, registers are 64-bits. This number is called the word size. A cpu only has a handful of registers, and an even smaller number that can be used for general purposes. For example, one register is the instruction pointer, called EIP on x86 and RIP on x64. This is an example of a special purpose register.

A computer generally accesses memory by means of cpu instructions that move values between registers and memory. To multiply two numbers in memory, it first might load them into registers for example. This is why x64 has a 64 bit address space. Because these instructions have to reference memory. And since the registers are 64-bit, it can reference an address that's 64 bits.

Things like chars, ints, etc are higher language level concepts. A char is 1 byte (8 bits) because that's what the C language says (If we want to be pedantic, it says that a char is at least bits, so in theory you can't rely on sizeof(char) == 1). How the compiler generates the code to make these operations possible is up to it. But it always does so through registers that are exactly the size of one word.

But a byte is always 8 bits, independent of architecture. That's just the definition of a byte.


The smallest addressable unit of memory is 1 byte. Remember that every operation has to go through registers, and the registers are 64 bits or 32 bits depending on platform. But the registers are subdivided. On x86, EAX is 32 bits. But you can address the low 2 bytes of this register as ax. And you can address the high and low bytes of ax as ah and al, respectively. But you can't go smaller. So 1 byte is the smallest unit of memory you can load.
Believe it or not there are architectures (and thus compilers targeting said architectures) that violate that. I can't remember which one - I believe it was a Texas Instruments compiler - the C55x. sizeof(char) returned 1 (I believe the standard dictates that sizeof(char) must always be 1, and you should be able to rely on this, though whether any given compiler is actually standards compliant is another topic), and it was using 16 bit bytes - sizeof was returning values in terms of multiples of 16 bit bytes due to their byte being 16 bits long. So no, you technically can't rely on 1 byte being 8 bits - except you basically can for the large large majority of current architectures.

For the purpose of 99% of programmers, you can basically state that 1 byte is 8 bits (and really, it is pretty much ubiquitously accepted as such) and they'll likely never encounter a difference from that. You can read more here.

Let me fix that link for you;

https://gist.github.com/anonymous/912c54befa6898386838

The link that you shared is the link to pull down your gist as a git repo. Which just allows you to make a local copy with the popular version control tool "Git".

...one reason I'm reluctant to recommend Github for new programmers until they're ready for version control and awkward command line tools.

Yes, I know many people that conflate git and Github, and don't realize that repositories can exist outside the confines of github (and that git itself of course exists independent of github).
 

Nesotenso

Member
In x86, registers are 32-bits. In x64, registers are 64-bits. This number is called the word size. A cpu only has a handful of registers, and an even smaller number that can be used for general purposes. For example, one register is the instruction pointer, called EIP on x86 and RIP on x64. This is an example of a special purpose register.

A computer generally accesses memory by means of cpu instructions that move values between registers and memory. To multiply two numbers in memory, it first might load them into registers for example. This is why x64 has a 64 bit address space. Because these instructions have to reference memory. And since the registers are 64-bit, it can reference an address that's 64 bits.

Things like chars, ints, etc are higher language level concepts. A char is 1 byte (8 bits) because that's what the C language says (If we want to be pedantic, it says that a char is at least bits, so in theory you can't rely on sizeof(char) == 1). How the compiler generates the code to make these operations possible is up to it. But it always does so through registers that are exactly the size of one word.

But a byte is always 8 bits, independent of architecture. That's just the definition of a byte.


The smallest addressable unit of memory is 1 byte. Remember that every operation has to go through registers, and the registers are 64 bits or 32 bits depending on platform. But the registers are subdivided. On x86, EAX is 32 bits. But you can address the low 2 bytes of this register as ax. And you can address the high and low bytes of ax as ah and al, respectively. But you can't go smaller. So 1 byte is the smallest unit of memory you can load.

thanks for the breakdown. I was aware of most of what you wrote. I was wondering if memory addresses outside of the cpu registers load only a byte. But as you said the smallest addressable unit is a byte. all the answers here have helped
edit: never mind got it.
 
Let me just get back to this. I hope I haven't scared you off with talk of "gists".

know there has to be a way to write code that reads the selected meals and calculate the total price, but I'm not sure where to start.

You want to put every variable that you want to calculate into a data structure. One way of doing this would be with an array, which is just an ordered collection of items. The first element can be found at position "0".

The Visual Basic documentation on Arrays

Read all the documentation. It will tell you all you need to know about this data structure.

Then you want to iterate through the array (note the "Iterating Through An Array" subheader in the documentation I linked to above) to add each price and store the summed price in another variable.

Learn to love your documentation. MSDN is good, they have lots of great resources for Visual Basic, C#, and other programming languages backed by Microsoft.
 

XenodudeX

Junior Member
Let me just get back to this. I hope I haven't scared you off with talk of "gists".



You want to put every variable that you want to calculate into a data structure. One way of doing this would be with an array, which is just an ordered collection of items. The first element can be found at position "0".

The Visual Basic documentation on Arrays

Read all the documentation. It will tell you all you need to know about this data structure.

Then you want to iterate through the array (note the "Iterating Through An Array" subheader in the documentation I linked to above) to add each price and store the summed price in another variable.

Learn to love your documentation. MSDN is good, they have lots of great resources for Visual Basic, C#, and other programming languages backed by Microsoft.

Arrays, huh?. That looks really hard D:

I should of been more specific, but the assignment tells me to Calculate a running total of the food item(s) selected.
This is my program:





So the idea is that you choose from either Breakfast, Lunch, and/or Dinner, select your meal, and have the price of the meal, the subtotal, tax, and total show up on the receipt.

We haven't gotten to the point in the class where we're using arrays, so I'm pretty sure there's another way ( say If/If Else/If ElseIf blocks And/oR Select Case/Select Case Else blocks maybe?)
 
The Array's not a hard thing, in of itself.

I think diving into official docs can be intimidating considering the way they write is very... dry, sometimes clinical. And Visual Basic today has the added caveat that it builds on Microsoft's .NET infrastructure, and the official MSDN documentation isn't shy about hiding those more complex details. VB is not as friendly to newcomers as it once was.

Eventually, documentation reading is a skill to pick up. As a programmer, the official documentation is always the first place I go to check out a programming feature, everything else out there builds on that.

ANYWAY!

That's cool, we can do this in this given way, with conditional statements (if, else, select case, like you were saying);

Try reading the selected values (checkboxes, radio buttons) with conditional statements, and keep a variable off the side to hold the computed total. That variable will hold your subtotal.

As you read the values, add the corresponding quantity for that item to that subtotal variable.

When you're done reading every possible thing on the form, read what's within that subtotal variable, and display that as your subtotal. Then put another variable aside for the total, add tax to subtotal, and show the total in your receipt. Then, you're good.
 
Man, I was just taking a quick break from this VB class I'm taking on OT because I've been scrambling through my text book and staring at VB for the better part of an hour, then I saw this thread, maybe one of you who knows more than I can lend a hand..

I'm building a calculator, basic stuff, but the assignment calls for the calculation to be displayed (if 2+2 is calculated, the result box must show 4, but another textbox needs to display 2+2=4 and so on) and I have no idea how to get that to display, well..I have a bit of an idea but its just not coming together.

Additionally, this calculator is supposed to save 10 operations with a clear memory button, this is probably going to be much more troubling for me, but I'll start with the easier one hah. So far the calculator works fine, which took all of ten minutes, but the nuances I cannot even begin to figure out. Any help would be appreciated.
 
Man, I was just taking a quick break from this VB class I'm taking on OT because I've been scrambling through my text book and staring at VB for the better part of an hour, then I saw this thread, maybe one of you who knows more than I can lend a hand..

I'm building a calculator, basic stuff, but the assignment calls for the calculation to be displayed (if 2+2 is calculated, the result box must show 4, but another textbox needs to display 2+2=4 and so on) and I have no idea how to get that to display, well..I have a bit of an idea but its just not coming together.

Additionally, this calculator is supposed to save 10 operations with a clear memory button, this is probably going to be much more troubling for me, but I'll start with the easier one hah. So far the calculator works fine, which took all of ten minutes, but the nuances I cannot even begin to figure out. Any help would be appreciated.

I'm not quite sure where you are stuck here, but I think it would help iiiif;

1. You take a little time to sketch out ideas in a notebook, regarding what you think could work. I do this all the time, I don't usually spend more than a few hours at the computer just banging things out and seeing what happens. The notebook is a good way of keeping your thoughts together, and avoiding repeating stuff or losing your train of thought. Always good to look back to see what you've tried before coming up with new ideas.

2. You could list a set of goals regarding exactly what nuances you want to tackle first.

3. You could share about what was the last thing you learned about VB. If the array is foreign to you, let us know so we can avoid solutions involving data structures. (though I'm sure your professor would be impressed if you used one somehow.)
 

XenodudeX

Junior Member
The Array's not a hard thing, in of itself.

I think diving into official docs can be intimidating considering the way they write is very... dry, sometimes clinical. And Visual Basic today has the added caveat that it builds on Microsoft's .NET infrastructure, and the official MSDN documentation isn't shy about hiding those more complex details. VB is not as friendly to newcomers as it once was.

Eventually, documentation reading is a skill to pick up. As a programmer, the official documentation is always the first place I go to check out a programming feature, everything else out there builds on that.

ANYWAY!

That's cool, we can do this in this given way, with conditional statements (if, else, select case, like you were saying);

Try reading the selected values (checkboxes, radio buttons) with conditional statements, and keep a variable off the side to hold the computed total. That variable will hold your subtotal.

As you read the values, add the corresponding quantity for that item to that subtotal variable.

When you're done reading every possible thing on the form, read what's within that subtotal variable, and display that as your subtotal. Then put another variable aside for the total, add tax to subtotal, and show the total in your receipt. Then, you're good.
*sigh*

I don't know how to do any of that.
 
Top Bottom