Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you explain the question a bit better, please? It isn't clear just what you are looking for, especially what you mean by 'execute first'. That last part sounds like your professor's instructions to you rather than a part of the question.

I assume you are asking, how would you write the code for this, but frankly, the first part sounds trivial; you would simply assign the first variable's value to the temporary variable, then assign the second variable's value to the first variable, then finally assign the temp variable's value (which is holding the first's old value, remember) to the second variable.The only possible complication I can see is if you are writing it as a function, in which case you would have to pass the variables by reference (that is to say, using pointers to the actual variables rather than copies of the values).

As for swapping without a temporary variable, the usual approach in C is to use a trick involving the XOR operator (^), but I'll leave it to you to figure it out. I will warn you that the XOR trick isn't necessarily more space efficient than the temp variable version (because of certain optimizations the compiler can use involving internal registers), and it has a potential to backfire - if the two values are already the same, then XORing them will give a result of zero. It's the sort of kludgy optimization that you are unlikely to bother with on a modern system, because …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, tuples are mainly used by the Python language itself, for certain types of operations where lists would too slow, or where the immutability of tuples is helpful. For example, multiple return values are actually passed as a tuple, which can either be assigned as a single value or 'unpacked' across multiple variables.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The problem is that you are calling the is_divisible() function, and then, on a separate line, testing whether True is true, which will always be the case. What you want to do is call the function as part of the if: clause itself:

    primes=[]
    for n in range(2, N+1):
        if is_divisible(n, primes):
            primes.append(n)
    print(primes)

This has the effect that the return value of the function is used as the condition of the if: statement.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, we don't do other people's homework for them. Second, we don't do other people's homework for them. And third, we don't do other people's homework for them. Sensing a pattern here yet?

No one here will simply hand you a solution on a silver platter. If you show us what you've done, what you've tried to do, and what problems you've had with it, then we'll be happy to help. If you have specific questions, we can answer them, or at least point you in the right direction. If you have a program with a bug you can't swat on your own, we'll be glad to assist, so long as you pay attention to the forum rules and post sensible questions in an intelligent manner that we have some reasonable hope of answering.

But just cutting and pasting an assignment into a message, without even prefacing it with something like, "I have this homework problem that I can't solve...", is likely to get you booted from the message boards here and elsewhere - if you're lucky. What happens to you if you are unlucky is... well... let's just say that this guy probably won't be trying that again, on that forum or this one.

And if you think your professor won't catch you trying: think again.

We take this issue seriously here. Very seriously. Asking us to do homework for you is a grave breach of academic ethics …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Can you be a bit more specific about what is actually happening, then? Simply saying, 'This is not helping' gives us little to go on.

#include <stdio.h>
int main(void)
{
    int n, prod, even;
    prod = 1;
    n = 30;
    for(even = 2; even < n; even += 2)
    {
        prod *= even;
        printf("Product of all the positive even numbers less than %d is %d\n", n, prod);
    }

    return 0;
}

You might note a few things here:
* I replaced void main(void) with int main(void). While 'void main' is a common idiom, it is strictly speaking incorrect, or at least not portable.
* I corrected the assignment for n; as you had it, it was a comparison, not an assignment, and had no effect on the rest of the program.
* I used the accumulate-assignment statements for the increment and the product, and eliminated an extraneous increment.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Keep in mind that there is difference between the general algorithms, and the archive file formats which are their concrete realization. For any given algorithm, there are more than one possible representation of the compressed data. It is only when you have a specific format that you can meaningfully talk about detecting the format from the file metadata. For example, two different archive formats may both use LZW compression for part of their formats, yet the actual formats could be quite different.

EDIT: I was wrong about Zip and GZip. Sorry if I misled anyone.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It may also help to read up on indent style (also called brace style) to help clarify the issue at hand. There are several ways to format C++ code, all of which have their advantages and disadvantages; the most important things are that you use a style that is widely known, and that you are consistent in applying your chosen style throughout a given program.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It's been a while since I've been there, but I used to be a regular.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I think there is some confusion about the nature of operating systems going on here. That is natural, as much of the OS is hidden from view, while most of the things people think of as being part of the OS are actually separate programs (or at most sub-sections of the OS proper). There is a definite disconnect between what OS developers (both professional and hobbyist) think of as 'the operating system' and what most users and client-programmers think of as the OS.

Generally speaking, most people think the operating system is the Graphical User Interface and the Window Manager, the upper-most levels of the system. This isn't really the case, however; in fact, these aren't necessarily part of the operating system at all. For example, most Unices - Linux, FreeBSD, and MacOS X included - do not have a GUI or Window Manager as part of the operating system; in fact, the entire user interface, including the text shell, runs as a set of user-level applications. Even in Windows, most of the windowing system is run in user space.

Conversely, to a serious OS developer, the real meat of the OS is in the kernel, the lowest level part of the system. This is where things like memory management and process scheduling take place, and but it is only a very small part of the whole system.

Just to put the issue of operating systems in different programming languages into perspective, there is a page on the …

ddanbe commented: Well explained. +14
Assembly Guy commented: Nice. I'm never bothered to explain so clearly +4
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I think you'll need to clarify things a bit before anyone can give you a helpful answer. Is your question about how you would call this function in general, or specifically about the difference between calling it in C and calling it in C++? I ask because, in most cases, there wouldn't be a significant difference - though the function itself would probably be defined differently, using an ofstream rather than a FILE, and you could redefine the index structure (or more likely, class) using string objects, but that's a different question altogether.

If you need help understanding how functions are called in general, this post should help explain the relationship between functions, function prototypes, and function calls.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I have to agree with the consensus that as a practical skill, assembly language is not very useful. I would, however, argue that knowing something of assembly programming in general does help you understand some of the things going on inside of a compiled program, especially if you dig into the arcana of systems programming and/or compiler design. I see it as being something that is mainly useful for the insight it gives rather than for its actual practical use. Thus, I would recommend learning assembly programming as an adjunct to some broader topic, eventually, but not to put any real priority to it.

That having been said, I will mention that one of the best introductory programming texts I know of - Assembly Programming Step by Step by Jeff Duntemann - is all about assembly programming for Linux, while the classic Knuth texts all use assembly (for a simulated processor) in their example code. You won't regret learning assembly, but unless you are writing either operating systems or compilers, chances are you'll never need to know assembly. It is purely optional with modern computers, and even embedded systems are mostly programmed in C or some other HLL these days.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I know you have a working program as of now, but you'll still want to try and understand the difference between a function prototype and a function call, and between the formal parameters and actual arguments.

First for prototypes. These are, basically, declarations describing how the function's signature, which is to say, it's name, return type and parameter types. You need to have the prototypes ahead of any calls to the function, so that the compiler knows that there is in fact a function names so and so that takes such and such arguments.

If you look at a header file such as <iostream> or <cmath>, you will see a large number of function prototypes, for the standard library functions. These functions are, broadly speaking, the same as those you would write yourself, they just are part of the standard library. As I explain here, headers are used mainly as a way of getting large numbers of declarations and prototypes into programs without having to enter them in manually each time.

When you write a function prototype, you need to put the types of the return value and the parameters, and optionally, the names of the parameters as they are in the actual function implementation. The names of the parameters aren't really important to the prototype, but they do make it easier to understand.

When you then write the function's implementation, you need to have it's parameter types and return type match those of the prototype, or else …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The problem is that, just as with division, taking the modulo of a number by zero is undefined; what you are actually getting is a division by zero exception, as internally, both division and modulo (or rather, strictly speaking, remainder) are calculated using the same assembly instruction. Thus, this is one place where you actually want to initialize b to one instead of zero. No, on second thought, start at 2 - there's no point in starting at 1, as every number is divisible by that, and it would give you a false negative for everything.

I might also suggest that you only iterate b from 1 to ciel(sqrt(a)), as you know that no prime divisor of a number is going to be more than that number's square root.

 for(b = 2; b <= (int) ciel(sqrt(a)); b++){

Finally, you might want to actually print the results when you find a prime number other than 2. Just sayin'.

Anyway, here is a simplified version of your code, though it assumes that the C99 <stdbool.h> library is available (it should be, with any compiler newer than, say, 2004). It isn't actually tested, but it should fix most of the problems in the original.

#include <stdio.h>
#include <stdbool.h>

int main() {

    int a, b, c;
    bool composite;

    printf("2, "); 

    for(a = 3; a <= 100; a += 2) {
        composite = false;

        for(b = 2; b <= (int) ciel(sqrt(a)); b++) {
            c = a % b;
            if (c == …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Congratulations on finishing it, though once again, more detail on how you fixed it would have been appreciated.

Also, just as a friendly reminder: when you do finish with the issue at hand, please mark the thread as closed, so that everyone knows you've solved the problem. TIA.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would mention Structure and Interpretation of Computer Programs as a good starting place, but it's a controversial sugestion; on the one hand, it does an admirably job of covering programming in the small, starting from the ground up and moving alll the way through several complex topics. On the other hand, it is based on a very unusual language (which they use a fraction of, at that) and takes an approach that is highly ideosyncratic; many programmers find it too divorced from daily practice to be relevant. On the gripping hand, that sort of more abstract approach is exactly what many programmers are lacking - tunnel vision is rampant among ordinary coders, and the sort of sweeping vision SICP gives is an excellent antidote to that. Your call.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

mukulnimker7751: would you mind explaining the problem in greater detail, i.e., the circumstances in which you need to access the server this way? It would be much easier to help you if we had a better idea of what is actually going on; as things are we can only answer in generalities.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Hint: assuming that your iterator variable is i, try using i += 2 instead of i++. In other words,

for (i = 2; i < final_value; i += 2)

This will step you two values at a time istead of just one.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Questions about OS development are a bit outside the usual range for this forum; you might want to try the OS Dev forums at OSDev.org, as they are experts in the subject. Note that you need to tread lightly there, as they are rather rough with newcomers and do not suffer fools gladly. Still, the Wiki there has answers to many of the questions you are likely to have.

As for your specific question, the real issue is this: even if you are running this on a Windows development platform, your are presumably running it with an emulator such as Bochs, or through a virtual machine client such as Virtual PC or VMWare. In either case, the emulator/VM will behave as if it were running on bare metal; as far as your code is concerned, there won't be any Windows system to call out to. Thus, any handling of system services will have to come from you and you alone, or from the hardware BIOS (which will only help in a 16-bit system and is of minimal value anyway).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Asking "What's the best programming language?" is much like asking "What's the best airplane?" - it entirely depends upon what you want to do with it.

As Nelson-sensei once wrote, it is in some ways closer to asking, "What's the best religion?" Programmers often commit themselves to their tools, well beyond reason. It is perhaps less true today, but languages are often the subject of both prejudice and egotism. While no one language is best for all purposes, it is not uncommon for a programmer to try to use the language which he or she had 'bonded' to for all purposes, simply because they can't see the limitations of their tools.

ddanbe commented: Well said. +14
rubberman commented: Ditto what ddanbe said. See my post below. +12
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Your second (output) loop has an inner loop that looks to have been intended to iterate through the five test values; however, you then unrolled that loop, making the inner loop unnecessary. The solution is either to eliminate that inner loop altogether:

    for (int a = 0; a < grades.length; a++) {
        System.out.print(
          grades[a][0] + "\t" +
          grades[a][1] + "\t" +
          grades[a][2] + "\t" +
          grades[a][3] + "\t" +
          grades[a][4] + "\t" +
          percentage(quiz1, quiz2, midterm_exam, final_exam) + "%\t\t" +
          grade(percentage)
        );
      System.out.println("\n");
    }

or try to fit the unrolled values back into the loop (note the subscript before the .length property):

    System.out.println("Name\tQuiz 1\tQuiz2\tMidterm\tFinal\tPercentage\tGrade");
    for (int a = 0; a < grades.length; a++) {
      for (int b = 0; b < grades[a].length; b++) {
        System.out.print(grades[a][b] + "\t");
      }
      System.out.print(
        percentage(quiz1, quiz2, midterm_exam, final_exam) + "%\t\t" +
        grade(percentage) + "\n"
      );
    } 

Note that this does not address the problems with the first loop.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Several of us can help you, but you'll need to post what you've done so far. To quote DaniWeb's forum rules:

Do provide evidence of having done some work yourself if posting questions from school or work assignments.

As I said, we will provide assistance. We won't hand you a solution to a homework problem for no effort on your part, however. Show us your work, and we'll help you fix it, but the community's ethical guidelines won't allow us to do more than that.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Basically, yes, though even that can be carried too far... as I've learned myself from times I've gotten dinged for overdoing it. It is often tempting to simply fix the whole program without explaining it, which is almost as bad as writing it from scratch. It is best to try and explain the problems with the code, and encourage them to fix it themselves, but that can be frustrating for both them and you. It takes a bit of practice and time to find te balance between helping too little and doing too much.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A few things to take note of:
* First off, this code appears to be C, not C++. Perhaps one of the moderators can move it over to the correct forum?
* There are two back-quote characters on line 13 that don't belong there.
* Variable-length arrays have to have to take a variable that is initialized before the array is declared (the main purpose of VLAs is to allow you to have array sizes set by a function parameter). Thus, you need to have initializers for T and j, before they are used. In any case, there is no reason to have some of these as VLAs, since the value of T is constant. As for the ones declared with j, well, that simply isn't going to work as you seem to expect.
* Arrays in C are zero-indexed, not one-indexed, and you seem to be going out of your way to treat them as one-indexed. It would be easier simply to use them as zero-indexed and be done with it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

give me ur email id and i will send it to u within 3 days

Please, please, please don't post this sort of thing. Aside from the use of SMS-speak, and the fact that you are directly offering to help someone cheat, asking for someone's e-mail address is both rude and potentially dangerous (e-mail harvesters are impossible to block, so posting an e-mail address in a public forum poses a risk of spam or identity theft). It is also against DaniWeb's general policy of keeping things public so that everyone may benefit from the answers given.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, I would strongly, emphatically recommend replacing the call to gets() with fgets(). The gets() function lacks boundary checking, and presents a substantial risk of buffer overflow.

Second, the delimiters for strtok() are incorrect; you presumably meant '\n' (the newline character) rather than '/' and 'n' (two separate characters). This would explain the problem you are experiencing, as right now it is truncating any word with an 'n' in it.

Third, in C, you can't have a statement followed by a declaration inside of a block. thus, you need to move the decalaration of pch to the line above the [f]gets().

Finally, I'll recommend a way of simplifying the program: in the declaration section, add the following declarations:

    int i;

    const struct {
        char* cmd;
        int code;
    } commands[] = {{"exit", EXIT}, {"dir", DIR}, {"copy", COPY}, {"type", TYPE}, 
                     {"del", DEL}, {"ren", RENAME}, {"rename", RENAME}, {"mkdir", MKDIR},
                     {"cd", CD}, {"rmdir", RMDIR}, {NULL, 0}};

You can then use this table as a lookup table for the commands, and loop through it like so:

    // TODO: Assignment 1 - Part 3 - Find and return command in commandTable that matches argv[0]
    for (i = 0; commands[i].cmd != NULL; i++) {            
        if (strcmp(argv[0], commands[i].cmd) == 0) {
            return command[i].code;
        }
    }

    return NONE;
}

(This assumes that the command codes are integers; if they are an enumeration of some kind, you would want to change the declaration of code to match.)

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

How hard it will be depends on just how ambitious you are, and what languages and tools you intend to use. Is there a specific type of game you are considering learning how to make? As for where to find information, well, GameDev.net is probably a good resource, as it's a good deal more specialized and has a large number of articles and tutorials. Another to consider is devmaster.net, which is smaller but a bit more beginner-friendly.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Uhm, all that return does is end the function. Since command is optional, not required, simply omitting the command keyword argument would do the trick. OTOH, if you think you absolutely need a function there (e.g., as a placeholder), you can use something like this:

def empty_command:
    pass

Which has the effect of simply ending the function.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

DarrelMan: Did you mean to post this in the C forum? While it is certainly possible to write a shell in C++, most OS courses use vanilla C for such projects. If you are using C++, then you ought to be able to use the overloaded equality operator to compare the strings instead of strcmp(), which, given that you are looking for strict matches, should work for your purposes.

Mind you, if the goal is to write a shell, then I'm a bit confused over your variable naming. Conventionally, *argv[] is the name of a command line argument to the main() function, but beyond being a convention there's nothing special about the variable name argv. Still, one would normally assume that argv is a command argument to the current program, in which case argv[0] would be the name of the shell program itself, not the name of a program or shell operation. If, OTOH, you are using argv for the name of the array of strings which the shell reads in from stdin, and then parses to get the command line, then it is somewhat misleading to call it argv, as it can be confused with the shell's own argv argument.

To clarify what I mean: if your shell is named, say dmsh (for "DarrelMan's Shell"), then to have it running as a shell, you would run the program from the existing shell as

$ dmsh

Let's further assume you used ']' as the prompt (old-time Apple II …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Assuming that you are creating a new file, then the simplest solution is just to name the file testfile.html to begin with:

std::ofstream FileOne("c:\\testfile.html");

The C++ file I/O works the same no matter what the file extension is; a 'text file' is just a stream of bytes which is interpreted as character data, after all.

OTOH, if there is an existing file named testfile.txt already, and you want to rename it to testfile.html, then the easiest solution is to open testfile.txt for reading, and testfile.html for writing, and copy the data from the former to the latter:

std::ifstream infile("c:\\testfile.txt");
std::ofstream outfile("c:\\testfile.html");
std::string temp;

while (infile.good() && outfile.good())
{
    getline(infile, temp);
    outfile << temp;
}

If you absolutely need to rename the file in place, then you need to use the <cstdio> function rename():

int result = rename("C:\\testfile.txt", "C:\\testfile.html");

I hope that one of these is what you are looking for.

daino commented: Great comprehensive answer +3
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Actually, the simplest solution is to use a static local variable:

int call_counter()
{
    static int count = 0;

    return ++count;
}
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

ALso, the reason there is no main() method is simple: the program is written as an applet (a web-based program meant to be run in a browser) rather than a stand-alone application - something you would know if you were the original author of the program. I am assuming you are following a tutorial of some sort and got stuck, right? A rather outdated tutorial at that; not only is the older AWT Applet class deprecated in favor of the Swinf JApplet, but applets in general have fallen by the wayside for the most part.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As an aside, I noticed that you have posted to both here ande DevShed with the same problem. FYI, cross-posting is generally frowned upon, as it leads to duplication of effort. You should only post to one forum at a time, and only re-post elsewhere if you think you have exhausted the possibilities there, and if you do cross-post, always give a link to the other fora so that everyone can see what was done before.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A minor point unrelated to the question: the cout object and it's selectors only found in C++, not C.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As an aside: given that you are always allocating the same amount of memory for each of the arrays, and you never free() them, is it really necessary to use dynamic allocation for the arrays? What I mean is, with the code as it is now, you could just as easily declare them as

int temp[20],thick[20],area[20],cond[20],total_temp,n,i;

Is there some reason for dynamically allocating them that I'm simply missing?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, since you don't mention what operating system you are running under, I will have to assume you are using Windows, though the answer for Linux and MacOS are more or less the same anyway. With Windows, the only Java compiler of importance is the one from Oracle themselves; under Linux there are a few other options, but generally speaking you want the Oracle release as well.

What you want to do is install the Java Development Kit, Standard Edition for your system.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There are a number of problems with this code, but the most important is that there is a syntax error in the increment part of the inner for() loop.

     for(j=65;j<=i;j++;count++)

As things stand, this code shouldn't compile; the third semi-colon should be just a comma.

     for(j=65;j<=i;j++,count++)

This isn't the cause of the problem, however, assuming it compiles at all. The real problem is that you are setting j to 65, then comparing whether that is less than or equal to i, the value of which is known to be less than 10 (because of the condition of the outer loop). This means that the body of the inner loop will never execute.

Even if it did, there are problems with that loop body. You are declaring count as an int value, which means that it is at least 2 bytes wide; but then you are passing it to printf()'s formatting string as a char value, which is defined as being no more than 1 byte wide. While this may appear to work correctly in some compilers when running on a little-endian processor (such as the PC), it is not really correct, and not guaranteed to work. Most modern C compilers will check the formatting string and warn against this kind of risky conversion, in fact. It would make more sense simply to declare count as a char value, especially since you are dealing with values below 0xF0 (decimal 127).

There are also some problems …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The (float) part is a cast; it converts the integer value of (i + 1) (note how I had changed i to an int ealier?) to a float value. The reason I did this was because otherwise it would have been compilede as integer division, which wouldn't give the desired values.

As for the += operator, it is what is called the accumulate-addition operator, and what it does is it adds the value on the right-hand side to the variable on the left-hand side. it is a shorthand for

sum = sum + (i / (float) (i + 1));
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Conceptually, a string is an object that holds a piece of written text. The name 'string' is historical, and refers to the concept of 'string rewriting', a mathematical technique for analyzing sentences in an abstract grammar; the intended mental image is of pieces of paper held together by a (physical) string, which was an early way of manipulating character strings before computers.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

ajike: Are you certain that the box you are trying to connect to has a telnet server running, and that port 23 isn't being blocked by the firewall on either system? Most system installations disable telnet by default these days, because of security concerns.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Finding a number's cube is simply a matter of multiplying it by itself three times:

double cube(double x)
{
    return x * x * x;
}

Are you sure you didn't mean the cube root?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

One piece of advice I can give is that, whenever you find yourself using several variables of the form nameN, consider refactoring them as an array or an ArrayList. The hang0, hang1, hang2,... hang10 variables in particular stand out as something where a number of things would be simplified if you used an array for them.

Similarly, given that you are just using them to initialize an array, there is no need to have the individual letter buttons declared separately. If you really need to be able to refer to them by the letters themselves - which I don't believe you ever do - you could easily use a HashMap for that purpose instead:

private HashMap<char, JButton> letterButtons = new HashMap<char, JButton();

// later, initialize the HashMap like so
for (char letter = 'a'; letter <= 'z'; letter++) {
    letterButtons.put(letter, new JButton(letter);
}

Note also that you cannot use a String as the index of a swich() statement; you can, however, use an enum, which I have done in the following version of your code:

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.border.EmptyBorder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

enum ActionType {Easy, Medium, Hard, NoMercy};

public class Hangman extends JFrame {

    private HashMap<Character, JButton> letterButtons = new HashMap<Character, JButton>();
    private JLabel trysRemaining;
    private int setTrysHere = 6; …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Given the sort of questions these are, there isn't much advice we can give that wouldn't constitute answering the questions.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

It's even better than that, actually; it is clear that the OP didn't even transcribe the questions correctly, as most of them are clearly incomplete.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Oh? What compiler were you using, and how did you coax it to produce raw binaries?

(On a guess, it was Turbo C, correct? And you simply created a .COM file? That would work, but it would be quite limited.)

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would strongly recommend not responding to threads that have been dead for over two years, especially when the answer you're giving is unquestionably incorrect.

Why is your answer wrong? Well, first off, it does not address the matter of loading the compiled code into memory, and more importantly, of loading it correctly. Unlike with assembly language, there really isn't any option with most compilers to generate raw binary image files which can be loaded directly into memory; rather the generated code is going to be in an 'executable' format that contains relocation tables and other information that needs to be handled before the actual binary can be computed.

Worse, on the x86 and x86-64 platforms, your answer pre-supposes 16-bit C/C++ code, which few modern compilers will generate. In order to run the 32-bit or 64-bit code which are the mainstays of modern operating systems, you would need to switch into protected mode (or long protected mode) before running the C code, which means that the page tables, interrupt descriptors, and so forth would have to be in place before calling the compiled code.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Can you please show us what you have trid so far, and what problems you are having?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Before I get into your actual code, I have a few comments and suggestions to make. First off, get rid of Dev-C++ and get Code::Blocks. Dev-C++ hasn't been updated in eight years, and the version of MinGW/GCC that comes with it is equally dated. You could update the version of GCC, I suppose, but Dev-C++ still would have the compiler options and settings from 2005; it is easier and better just to get an up-to-date IDE. Besides, Code::Blocks fixes several of the flaws in Dev-C++, such as closing the program console immediately after the program exits; in Code::Blocks, the console stays open until you hit a key or close it manually, which is a definite plus.

Second, use the modern forms of the standard C++ headers. Since 1998, the standard has called for the '.h' extension to be dropped from the stnadard header names, and for the C style library headers to be prepended with a 'c'. For example, <iostream.h> is now just <iostream>, while <stdio.h> and <stdlib.h> are now <cstdio> and <cstdlib>. This has been in general use since around 2002; there is no excuse to still be using the older header names in 2013.

Third, you need to be more careful about indentation. Your indentation and bracing are all over the place, making teh code nearly impossible to read. There is no reason for this: both Dev-C++ and Code::Blocks come with a plug-in that auto-indents your code for you. Please show some consideration for people who …

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

With suitable libraries to draw on, you can write most types of programs in Python, except for really low-level systems work (device drivers and so forth). The biggest disadvantage over C isn't in what you can or cannot do with it, so much as how fast the program is likely to run, but even that isn't a major disadvantage with modern hardware.

I know you were looking at photo-editing software, an I'll admit that while it is possible to write something like that in Python, most people wouldn't (though The GIMP, a major open-source photo-editing package, uses both Scheme and Python for scripting) because of the spee and memory limitations. OTOH, by the time you are ready to tackle something that size, you'd be ready to learn C anyway.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

A few notes:

  • You should always declare the main() function as type int, and return a value at the end of it. While some compilers do allow you to declare void main(), it is non-standard and non-portable. Don't do it.
  • The <conio.h> header and the functions it declares are not part of the standard library, and even for those few compilers which support it, vary greatly in the specific functions it supports. Avoid using it. In any case, a good modern IDE shuch as Code::Blocks shouldn't close the program window off immediately after the program is finished, so the getch() kludge shouldn't be needed.
  • Using a float to hold an integer variable is problematic, as floats do not have an exact represention for certain integer values. The variable i should be type int in this case, and cast to float when the division is made.
  • The whole section using the variable y is unnecessary, and since y is never initialized, it actually causes the computation to fail. You can safely remove the entire thing.

Taking all this into account, the follow should do what you want:

#include<stdio.h>
#include<math.h>

int main()
{

    int n, i;
    float sum = 0;

    printf("Enter nth term ");
    scanf("%d", &n);

    printf("sum = ");
    for(i = 1; i < n * 2; i += 2)
    {
        if (i > 1)
        {
            printf(" + ");
        }

        sum += i / (float) (i + 1);
        printf("%d/%d", i, i + 1);
    }

    printf(" = %f\n", sum); …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Would you please post what you've done so far? Without being able to see the code, it would be difficult if not impossible to give you any advice.