NathanOliver 429 Veteran Poster Featured Poster

That comes from mixing input types. Mixing cin >> with getline() will cause this. One way to stop it is to put cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n') after every call to cin >>. You will need to include the limits header for this to work.

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far. We will not do your work for you. Converting centimeters to meters and kilometers is a pretty simple process. I will give you a hint though. Since you are going to be dealing with very large numbers you should do this with strings instead of number types.

NathanOliver 429 Veteran Poster Featured Poster

If you are going to use either wchar_t or wstring then you need to use wfstream for file operations.

NathanOliver 429 Veteran Poster Featured Poster

Well ╠ is expressible by the ascii code of 204. As far as working with unicode you might want to look into the std::locale library.

NathanOliver 429 Veteran Poster Featured Poster

All of your code is compiled by the compiler. As far as you loop question is concerned look at this:

for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 5; j++)
    {
        std::cout << j * i << std::endl
    }
}

The above cout statement will execute 50 times. The inner loop executes 5 times for every loop of the outer loop. Since the outer loop runs 10 times that gives you 10 * 5 = 50. So when calculating how many times the code in the inner loop will run you take the number of times the outer loop runs and multiply it ny the number of times the inner loop runs. This holds true when adding any number of nested loops. If you have this:

for (int i = 0; i < 10; i++)
{
    for (int j = 0; j < 5; j++)
    {
        for (int k = 0; k < 20; k++)
        {
            for (int l = 0; l < 15; l++)
            {
                std::cout << "inner most loop executed" << std::endl
            }
        }
    }
}

The cout statement will run 15,000 times. You multiply all of the numbers of times each loop runs and you get 10 * 5 * 20 * 15 = 15,000

NathanOliver 429 Veteran Poster Featured Poster

You need to change all of your comparisons in your loops from <= end to < end. The reason for this is if i or p equals end then you are one past the end of the array and reading data that my not belong to you and thus returning the runtime error

NathanOliver 429 Veteran Poster Featured Poster

There was a thread that I participated in a few years back and maybe you will get some insight from it. It was a natural string comparison challenge by Narue. As an FYI I wouldn't post anything to that thread since it so old. http://www.daniweb.com/software-development/cpp/threads/259447/c-challenge-natural-sorting

NathanOliver 429 Veteran Poster Featured Poster

Yeah I wouldn't argue at that point.

NathanOliver 429 Veteran Poster Featured Poster

So you have a set that hold all of the line numbers a give word appears? Then you need to store all of the words in that text with thier related set in another container? If that that case the map should be keyed by the word and the set should be the data.

NathanOliver 429 Veteran Poster Featured Poster

I know that. He wanted the code so I told him to give me money. It was an unresonable request like him just asking for code.

NathanOliver 429 Veteran Poster Featured Poster

Give me money and you have a deal

NathanOliver 429 Veteran Poster Featured Poster

You could pipe the cmd text to a file and then parse that file for the information that you need.

NathanOliver 429 Veteran Poster Featured Poster

Okay. Now what?

NathanOliver 429 Veteran Poster Featured Poster

You are missing a return stament in your main function as well as a closing curly brace for the main function.

NathanOliver 429 Veteran Poster Featured Poster

@ OP if you have a compiler that supports c++11 than you can use the std::map initializer list constructor. It would change your code to loo like this

void ArcherArmor::ArcherArmor_shop(){
    soldier_armor = {//name, damage, price
            std::make_pair(1, Armor("Meito Ichimonji", 4, 150, 1)),
            std::make_pair(2, Armor("Shusui", 10, 230, 2)),
            std::make_pair(3, Armor("Apocalypse", 16, 300, 3)),
            std::make_pair(4, Armor("Blade of Scars", 24, 550, 4)),
            std::make_pair(5, Armor("Ragnarok", 32, 610, 5)),
            std::make_pair(6, Armor("Eternal Darkness", 40, 690, 6)),
            std::make_pair(7, Armor("Masamune", 52, 750, 7)),
            std::make_pair(8, Armor("Soul Calibur", 60, 900, 8))
        };
}
NathanOliver 429 Veteran Poster Featured Poster

The only way I know to make a pointer array with x values is the following.

int * numbers = new int[x];  // where x equals some integer number
NathanOliver 429 Veteran Poster Featured Poster

i am bit confused about the logic to calculate number of digits in a number!

What do you mean by number of didgits in a number? An armstrong number is only three digits. if you have a number xyz then x^3 + y^3 + z^3 = xyz for an armstrong number.

Are you having a hard time seperating out the digits from the start and stop numbers? If that is the case then you can break out the digits of a number as follows. note: I am storing the individual digits into an vector so they can be used later

std::vector<int> digits
int number; // this is the number we will get the digits out of example 371
while (number != 0) // once we get all of the digits stop
{
    digits.push_back(number % 10); // this gets the right most digit
    number /= 10; // this gets rid of the right most digit
}

// right now the vector holds 1, 7, 3
// if you want to have the digits in the vector reversed then use
// this needs the <algorithm> header included
std::reverse(digits.begin(), digits.end());
NathanOliver 429 Veteran Poster Featured Poster

??? Are you trying to ask a question?

NathanOliver 429 Veteran Poster Featured Poster

Okay. what do you have so far? You can take a look at this.

NathanOliver 429 Veteran Poster Featured Poster

Check this out Click Here

NathanOliver 429 Veteran Poster Featured Poster

What is fil3? You are oppening account.txt in inFile.open("account.txt",ios::in);

NathanOliver 429 Veteran Poster Featured Poster

Get rid of line 14. On the last time through your loop you will reach the end node which shouold be null. Then line 14 tries to access it and since it is null it will throw a fault.

NathanOliver 429 Veteran Poster Featured Poster

Nice find there vmanes.

NathanOliver 429 Veteran Poster Featured Poster

Try this and let me know If you get the second cout statement

#include <iostream>
using namespace std;

class A
{
private:
   int _dmember;

public:
   void func()
   {
     cout<<"Inside A!! "<<endl;
     cout<<_dmember; // 
   }
};

int main ()

{

    A *a=NULL;

    a->func(); // prints "Inside A!!!" 

    cout << "We are now outside a->func().  If you can see this then your program didnt crash

    return 1;
}
CoolAtt commented: yes it crashed +2
NathanOliver 429 Veteran Poster Featured Poster

No one is going to do your work for you. There is little difference in a do-while loop compared to a for loop. Yopu just have to make your own counter and take care of it with a do while loop versus a for loop. Here is how you can chnage a for loop to a do-while loop:

for (int i = 0 /*variables*/; i < 10 /* condition */; i++ /*increment section */)
    {
        //do stuff
    }

    // becomes

    int i = 0; // variable section
    do
    {
        //do stuff
        i++; // dont forget to increment the counter.  increment section
    } while (i < 10) // condtion 

Now that you have that you should be able to do it with a for loop and then once that is working you can convert the for loop to a do-while loop.

NathanOliver 429 Veteran Poster Featured Poster

So what do you have? What problem are you experiencing?

NathanOliver 429 Veteran Poster Featured Poster

Got beat to the answer. Ignore post.

NathanOliver 429 Veteran Poster Featured Poster

So besides the fact that your code is almost complete unreadable whats your problm?

NathanOliver 429 Veteran Poster Featured Poster

I actually prefer seeing int clocks_per_ms = CLOCKS_PER_SEC / 1000; to int clocks_per_ms = 1000;. It lets the person reading the code now exactly what you want to do. Also since it is a constant being divided by a constant it will be optimized away to int clocks_per_ms = 1000; at compile time.

NathanOliver 429 Veteran Poster Featured Poster

I'll throw in my two cents as well. I am currently going to college here in the states and from what I have seen in my classes most programmers are doomed. Our C++ class was basically C with classes at the end. I had a couple of java classes as well and it was not much better. Most of the time if your code produced the desired result it was acceptable. I only had one teacher that had any standard of what your code should look like. In my C++ class some people would turn in code that was 200 lines long that could write in 50. No care is given to teach students how to optimize or if sections of code are repeated they should be put into functions. The most depressing thing about the programing classes I took is that never once did we talk about the real world. Theory is all fine and good put if you have no idea how to apply what you know to real world problems what is the point? Isn’t going to collage supposed to prepare you for a career in your field of study? Most of the people I went to school with would need to forget almost everything they were taught because if they tried to code like they did in school in a job they would get fired. I just think it is a disservice for schools to start you off on the wrong foot. I have noticed that …

NathanOliver 429 Veteran Poster Featured Poster

Try putting the file were the .exe file resides.

NathanOliver 429 Veteran Poster Featured Poster

This is from line 023 double AreaOfTriangle
This is from line 102 double AreaOfTrianglw

Notice anything wrong? Also dont hijack and old thread with a new problem. Start a thread instead.

NathanOliver 429 Veteran Poster Featured Poster

What is the full error you are getting. Just posting 400+ lines of code and a partial error message as your title generally doesnt get you very far.

NathanOliver 429 Veteran Poster Featured Poster

In your function you need to declare a local variable to hold the sum of the array elements and then return that. You do not want to store the sum in n.

NathanOliver 429 Veteran Poster Featured Poster

what does the input to your program look like?

NathanOliver 429 Veteran Poster Featured Poster

How would you write code without using functions or classes? From what I know about code creation you want to compartmentalize your code as much as possible. Breaking it up makes it easier to maintain and affords you the ability to change code in one spot and have it apply to your entire project. Lets say you have an algorithm that does a transformation of a number to another number. If you had the code that does that in all of the places you need it that's bad. If you want to change it you would have to go to every spot in your code and change it. If you instead had the code in a function and you called the function every time you needed it then all you have to do is change the code in the function. Its the same problem with magic numbers in your code. If you are using a specific number all over the place in your code make it a constant variable instead of hard coding it everywhere. It makes updating your code a lot easier.

NathanOliver 429 Veteran Poster Featured Poster

Mike thank you once again. You have given me a lot of food for thought. I will defenitley look into using std::future and std::async.

NathanOliver 429 Veteran Poster Featured Poster

Thank you Mike. I always appreciate when you respond. I had a felling it was something along those lines. And I am using a mutex to protect the access to the queue. The following is the body of my thread function.

// global space
std::mutex mtx;

// function space
void DoTransaction(std::queue<int> & line, std::vector<int> & customersServed, int wait)
{
    while (!line.empty())
    {
        mtx.lock();
        std::cout << line.front() << "\t" << wait << std::endl;
        customersServed.push_back(line.front());
        line.pop();
        mtx.unlock();
        std::this_thread::sleep_for(std::chrono::seconds(wait));
    }
}

If you wouldnt mind answering a second question of mine I dont like the way I am using mtx. I have it declared globally and I hate having global variables. Should I instead declare it in main and pass it as a reference to the threads? Could it be declared statically in DoTransactions()?

NathanOliver 429 Veteran Poster Featured Poster

Hey Daniweb,

I have recently started working with threads in the c++11 library. I started with a simple dispatch mechanism where I have a queue and that would get passed to the threads and the threads would take turns emptying the queue. Since each thread needs to share the queue I am passing it by reference. My original code looks likes this and it wasn't working.

// what DoTransactions looks like
void DoTransaction(std::queue<int> & line, std::vector<int> & customersServed, int wait)
//...

//...
std::queue<int> line;
for (int i = 1; i <= 10; i++)
    line.push(i);

std::vector<std::vector<int>> returns(2);
std::vector<std::thread> threads;
for (int i = 0; i < 2; i++)
{
    threads.push_back(std::thread(DoTransaction, line, returns[i], i + 1));
}
//...

I was able to find that I needed to wrap objects that I want to be passed as a refernce with std::ref() and I got this

//...
for (int i = 0; i < 2; i++)
{
    threads.push_back(std::thread(DoTransaction, std::ref(line), std::ref(returns[i]), i + 1));
}
//...

My question is do I always need to wrap an object with std::ref() when I want to pass it by reference? Does this come from the fact that the call to std::thread is a constructor and it doesnt forwar the references to the function the thread runs?

NathanOliver 429 Veteran Poster Featured Poster

He doesnt need to. You are supposed to.

NathanOliver 429 Veteran Poster Featured Poster

Does this code actually compile? Your functions should like this:

returnType ClassName::FunctionName (Paramaters)
{
    // function code goes here
}

As far as your set cell function is concerned you could do it like

void NumberArray::setCell(int index, double value)
{
    arrayPointer[i] = value;
}

You should also make sure that you are accessing a valid location in the array but I'll leave that for you to code.

NathanOliver 429 Veteran Poster Featured Poster

On all of your loopps you are running to SIZE. If the user does not enter 100 elemtents then you will be using elements that have not been used. you need to change all of the for loops to run to count and that should fix it.

NathanOliver 429 Veteran Poster Featured Poster

you need to move test.close() from line 9 to line 12 and test2.close() from line 10 to line 13

NathanOliver 429 Veteran Poster Featured Poster

Post the code that you have now

NathanOliver 429 Veteran Poster Featured Poster

Nevermind. I Though I saw something but realised I was wrong after posting.

NathanOliver 429 Veteran Poster Featured Poster

Move line 6 to be in between lines 1 and 2. Move line 8 to be after line 10. You cant open and close the file while you are trying to write to it. Open the file once and close the file once.

NathanOliver 429 Veteran Poster Featured Poster

Are you trying to use a shared_pointer which has a count of how many objects hold the pointer?

NathanOliver 429 Veteran Poster Featured Poster

What errors are those?

NathanOliver 429 Veteran Poster Featured Poster

What values are you using for a, b and n?

NathanOliver 429 Veteran Poster Featured Poster

you need to move the curly brace from line 60 to line 49 to put the if statement on line 50 outside your while loop.