You've got the basics, now you need to use them to build up more and more until you have a complete solution. The next step is to make a function that evaluates a single term. Each term has this...
Type: Posts; User: rossipoo
You've got the basics, now you need to use them to build up more and more until you have a complete solution. The next step is to make a function that evaluates a single term. Each term has this...
This is what I did and it ended up working good. Thanks,
I don't have a list of perimeter points, I have a list of elements (squares) from my 2d array that are touching the perimeter, and they are not in-order because I am using a recursive method to find...
I have a two dimensional array with some of the elements marked, in essence like the image below. I want to calculate the points needed to draw an outline around the marked elements. In this case it...
You have all the right parts, yet the solution is unnecessarily complex.
A more concise solution. It only does one number, you should be able to make it repeat until the user types in an...
What's wrong here?:
if (!prime) {
cout << "The number is prime.";
}
There's probably more, but that's one thing.
The behavior of this program will not be correct if only a one or two digit number is given.
I'm not sure how you are representing the maze data. But you need to be keeping track of the steps you have taken as you traverse the maze. You could have an array, and each time you take a step, add...
The secret reffered to is a basic flood fill. Check Wikipedia.
You need to iterate through every cell, and attempt to do a flood-fill for white. If it's successful, you add to a numberOfAreas...
What probably was wrong is that somewhere in the code that you have simply as ..... , you are changing the size of vector v. If you change a vector, any previously created iterators will become...
The code needed for drawing the top and bottom rows is different than that needed for the middle rows. Therefore, it makes sense to separate it. It could be crammed into one loop, but it doesn't make...
Actually, having a function call itself recursively on invalid input is probably not the best method. Since you only want the instance with valid input to do anything, you may as well not be calling...
Here is an illustration of how much using loops can improve the readability of code. I'll use loops and gotos to solve a simple problem, creating a multiplication table:
Using for loops:
for...
Not directly, but you can use a string inbetween:
char input;
string inputString;
getline(cin, inputString);
input = inputString[0];
This could be because there is leftover in the input buffer after the cin >> input; line.
Using cin for anything other than strings can be unreliable. You could try changing the line cin >> input;...
Can you tell why it's staying in the same room? You can use a debugger to find out exactly what code is being run when. If you pay careful attention to the output, the exact point at which something...
The logic could be reworked. Like so:
while (true) {
// ... display possible directions for travel
// Get input and decide where to go next.
char input;
cin >> input;
It's quite simple really. Assuming this is your current code to move north:
player.location = player.location -> north;
All you have to do is change it to:
if (askQuestion () ) {...
Just like how you don't need a separate function to move north for each room, despite the fact that north is different in each room, you also don't need separate question functions. Instead you need...
argc (argument count) is an integer representing the total number of arguments, including the name of the application
argv is an cstring array with the arguments, argv[0] is the first argument...
Oh, that probably means that the linked rooms are not being initialized to zero. It was working for me in GCC, but it wasn't really proper coding; I should have added it before. To initialize them,...
Import?
Don't worry about that, just use include. I copy-pasted out of my "Test" project I use for anything random like this, so there was other unrelated code. Otherwise you can actually compile...
You could expand a room to be whatever you like. You want to be able to move around inside the room? Have monsters? Treasure? It's all up to you. You cam see the o ly thing I implemented was a name...
Here is a simple room class and a navigating application:
#import <string>
#import <iostream>
// A very simple room class
class Room {
public:
string description;
There is an excess semicolon after main(), and another after while(). Your code block brackets don't match. You always begin a block with {, and end with }. If you start, you must end it, therefore...