sfuo 111 Practically a Master Poster

You can use System.IO.Directory.GetFiles(DIRECTORY_NAME); which will return an array of strings that contain all the files (with full path) in that folder.

PulsarScript commented: Thank you +2
sfuo 111 Practically a Master Poster

I am not a Unix/Linux user so I am not 100% sure but after reading on GetOpt here and a GetOpt example here I would say the short answer is you must write myprogram.c -t file1 file2 file3 because it parses for options first.

sfuo 111 Practically a Master Poster

Line 18 of what you posted makes no sense. It will always select maximum = maximum in the trinary operator and you cannot declare a variable equal to an undeclared variable (even if you could it would be holding a garbage value).

Line 19 you are now saying that the low guess is equal to some mystery value and your high guess is the maximum tolerated error? and then your maxError is now set to 0 and never used within your helper function.

In your helper function the only two lines that make sense are the first two where you calculate the average and the resulting fifth power of that value. Other than that I do not fully understand what you are trying to do because fifthPower - x will not give anything useful the way you are using it (maybe if you used maxError in here somewhere then it would make sense, but then again you are setting that to 0.0).

Here is what I think you are attempting to do

#include <iostream>
#include <cmath>

using namespace std;

double fifthRootHelper(double x, double maxError, double low, double high)
{
    if (x == 1.0) //special case for 1.0
        return 1.0;

    double avg = (low + high) / 2.0;  //use 2.0 not 2 just for the future case of running into integer division without knowing
    double fifthPower = avg*avg*avg*avg*avg;

    if (fabs(fifthPower - x) < maxError) //if our new guess is within our error, return that as the answer
        return avg;

    if …
sfuo 111 Practically a Master Poster

I would suggest that you do not try to store all your information in labels, but rather have seperate variables that control the amount of each stat that your character has and then display those values in the labels.

I tossed together a quick example of how you can use buttons to increase and decrease the stats for your character. I am sure there are better ways of coding this but this should get you on track and going.

UI is here - http://i.imgur.com/zS0hM22.png

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DaniRPG
{
    public partial class Form1 : Form
    {
        Player me;
        Int32 remainingPoints;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            me = new Player();
            remainingPoints = 20;

            lblAgiPts.Text = me.Agility.ToString();
            lblIntPts.Text = me.Intelligence.ToString();
            lblStrPts.Text = me.Strength.ToString();
            lblStamPts.Text = me.Stamina.ToString();
            lblRemainingPts.Text = remainingPoints.ToString();
        }

        private void btnStrInc_Click(object sender, EventArgs e)
        {
            if (remainingPoints > 0)
            {
                me.Strength++;
                remainingPoints--;
                lblStrPts.Text = me.Strength.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnStrDec_Click(object sender, EventArgs e)
        {
            if (me.Strength > 0)
            {
                me.Strength--;
                remainingPoints++;
                lblStrPts.Text = me.Strength.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnAgiInc_Click(object sender, EventArgs e)
        {
            if (remainingPoints > 0)
            {
                me.Agility++;
                remainingPoints--;
                lblAgiPts.Text = me.Agility.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnAgiDec_Click(object sender, EventArgs e)
        {
            if (me.Agility > 0)
            {
                me.Agility--;
                remainingPoints++;
                lblAgiPts.Text = me.Agility.ToString();
                lblRemainingPts.Text = remainingPoints.ToString();
            }
        }

        private void btnIntInc_Click(object sender, EventArgs e)
        {
            if …
sfuo 111 Practically a Master Poster

Just a question.
Could you tell me how you thought this:

a[maxIndex] = a[r*N + r];

I mean the index r*N + r.
As I can see it gives the diagonal elements.
I didn't know about that!

The diagonal elements occur when the row index is equal to the column index. We use "r" in this case because we are iterating through the rows with the outer most for loop. If you write the matrix out on paper and try to come up with general solutions using only constants (N in this case) and variables that you are controling (r and c), you can come up with equations that you can input directly into your code.

Also, do you have a solution using the max value instead of the max index?

Because ,I can't figure why I couldn't get the proper max value.

You could use the max value but you will have to keep track of the column index of the max value (unless you want to scan through the columns after finding the max value to find it again and do the swap, which I think is a bad idea).

for (int r = 0; r < N; r++)
{
    //"Assume" maxValue is the first element of the row
    double maxValue = fabs(a[r*N]);
    int col = 0;

    //Check to see if the rest of the elements are greater than current max value
    for (int c = 1; c < N; …
sfuo 111 Practically a Master Poster

Not sure why you are switching values in the b array or why your swap function uses loops.

#include <iostream>
using namespace std;

int main()
{
    const int N = 3;
    double *a = new double[N*N];
    double *b = new double[N];
    double *x = new double[N];

    a[0] = 9;
    a[1] = 3;
    a[2] = 1;
    a[3] = 0;
    a[4] = 4;
    a[5] = 5;
    a[6] = 8;
    a[7] = 1;
    a[8] = 4;

    b[0] = 7;
    b[1] = 8;
    b[2] = 9;

    cout << "Before" << endl;
    for (int r = 0; r < N; r++)
    {
        for (int c = 0; c < N; c++)
            cout << a[r*N + c] << " ";
        cout << b[r] << endl;
    }

    cout << endl;

    for (int r = 0; r < N; r++)
    {
        //"Assume" maxIndex is the first element of the row
        int maxIndex = r*N;

        //Check to see if the rest of the elements are greater than current max index
        for (int c = 1; c < N; c++)
        {
            //If it is greater then set the max index to the current index
            if (fabs(a[r*N + c]) > fabs(a[maxIndex]))
                maxIndex = r*N + c;
        }

        cout << "Max = " << fabs(a[maxIndex]) << " idx = " << maxIndex - r*N << endl;

        //If the max index is not a diag then lets switch it
        if (maxIndex - r*N != r) //col != row aka diag
        {
            double tmp = a[maxIndex];
            a[maxIndex] = a[r*N + r];
            a[r*N + …
sfuo 111 Practically a Master Poster

If you want to make a console application (the black cmd window) you select the Win32 Console Application project type. If you do not want the console to show then you create a Win32 Project, if you are using SDL or GLUT then you can call some of their library functions to create a window and then you just pass in functions into a callback that they specify (if you follow a tutorial you will figure out what I'm talking about). If you do not use SDL or GLUT (or similar library bundles) then you will have to look into WinAPI and it is not fun because it is written in C and has all of Window's custom data types and functions.

I'm going to assume that you are starting with SDL. If you read Lazy Foo's first tutorial and select Window > Visual Studio 2010, he gives you a step by step of what you need to do to get started.

sfuo 111 Practically a Master Poster

Since you have just recently started learning C++ and I don't know what programming background you have. I would suggest that you learn the foundations of the language before moving on to graphics.

While you are learning the lanuage you should think of really basic "games" that you could complete in a console window (i.e. tic-tac-toe, blackjack, and other easy card games). These games will help you by making you use a many parts of the C++ language all together.

After you feel more comfortable with the language then you should really think about what IDE and graphics library you want to use. Alternativly you can use a game engine that will handle graphics, physics, sound, GUIs, and much more, but this depends on if you actually want to learn how to program or just make games that are bound by their engine. Personally I like to try to make my own "libraries" with the exception of a graphics library because that would be just crazy.

I use OpenGL and VS2012, however if you are just starting out I would suggest using SDL or another "simplified" graphics library. This way you are not spending lots of time learning the graphics library and instead you can focus on learning how to use the language and understand how a game works.

Here is the C++ tutorial website that I used to learn the language and I still use this website as a reference for the standard libraries.

Here

sfuo 111 Practically a Master Poster

If you are new to game programming then you should start with a 2D game. There is a massive gap between 2D and 3D if you plan on writing any of your own code (physics or other engine elements).

sfuo 111 Practically a Master Poster

If you don't want to use the table you can just use a program to print out what the char for those hex values would be.

#include <iostream>
using namespace std;

int main()
{
    char message[] = { 0x4B, 0x50, 0x7B, 0xF1, 0xF4, 0xF5, 0x5E, 0x50, 0x7B, 0xF1, 0xF4, 0xF5, 0x5E, 0x4B, 0x4B, 0x4B };

    for( int i = 0; i < 16; i++ )
        cout << message[i];
    cout << endl;

    cin.get();
    return 0;
}

The message is junk but maybe you can make something out of it. I'll let you run it and see what it is.

sfuo 111 Practically a Master Poster

Or instead of using an int array you could use a map (or unordered_map if you have a compiler that supports C++11).

Accessing the values would be exactly the same but instead of having an array with a size of 97 + 26 (because 'a' is 97 (as said above) and then you need room up until 'z') you would have a map with 26 entries. Obviously maps have overhead that a normal array does not, but I think it would be good to play around with some of the STL containers so that you know how to use them and what each of them can and cannot do.

#include <iostream>
#include <map>

using namespace std;

int main()
{
    map<char, int> myMap;

    for( int i = 0; i < 26; i++ )
        myMap['a'+i] = i;

    cout << myMap['c'] << endl;

    cin.get();
}

By the way (I'm sure you just wrote it out and didn't actually test it) you defined an int array of size 10 but assigned/accessed out of bounds (in your second example).

DeanMSands3 commented: While NathanOliver and AncientDragon give "correct" answers, this is probably the most useful. +5
sfuo 111 Practically a Master Poster

All three errors are from line 23 in your original post. If you read my post then you should have been able to correct that line and you would not have any more errors.

sfuo 111 Practically a Master Poster

There are a few things wrong with your code and you can make a few improvements too.

You are getting those errors because your syntax is wrong. If you wanted to input that equation it should look like cout << (storage_f_to_c - 32.0f)*5.0f/9.0f << endl;. So not only is the equation incorrect, but you had the multiplication operator with a closing bracket to the left (you would never see this in written math or input for a computer). Another problem is that you have "<<" at the end of the line and that is looking for a right-hand operand.

Some imporovements that you could make would be to use a variable like "input" to store both enter_f_to_c and enter_c_to_f (and if you were to expand this to Kelvin and Rankine then you would need loads more variables), also should make "result" hold the storage variations of these variables and the variables enter, a, and b can go into a single char variable called "option" and to select which equation to use you can check it with a switch() statement.

#include <iostream>
#include <cmath> //in C++ use cmath not math.h (this goes for all the standard .h headers from C)

using namespace std;

int main()
{
    char option;
    float input;
    float result = 0.0f;

    cout << "If you would like to convert Fahrenheit to Celsius,\n type the lowercase letter -a- (without the hyphens).\n If you would like to convert Celsius to Fahrenheit\n type the lowercase letter -b- (without hyphens).\n You …
sfuo 111 Practically a Master Poster

I think the biggest problem you are having is that the matrix you think you have is not the one you set up. As you can see I printed out the contents of the matrix and it is correct because I am adding the values of what row and column the for() loops are on.

I also see that you are kind of accessing the matrix with the x and y values being backwards. If you think about it rows are on the y axis and columns are on the x axis. For this example it will not matter since this matrix is <insert special name that I learned in linear algebra here>, which means that it is mirrored about the diagonal.

If you are going to use the new operator then you will have to store the resulting value that you are at in the matrix to a variable that you will return and then delete the memory allocated for the matrix (otherwise you will have a memory leak).

#include <iostream>
using namespace std;

int boundary2D( int xpos, int ypos, int xstep, int ystep )
{
    const int x = 4, y = 4;
    int matrix[y][x];

    for( int r = 0; r < y; r++ )
        for( int c = 0; c < x; c++ )
            matrix[r][c] = r+c;

    for( int r = 0; r < y; r++ )
    {
        for( int c = 0; c < x; c++ )
            cout << matrix[r][c] << " ";
        cout << …
sfuo 111 Practically a Master Poster

Why don't you treat this like two 1D boundary conditions (like the other post that was solved)?

If you create a position structure (just contains two ints or doubles for x and y position) then you can return that rather than creating a 4x4 matrix (which you did not allocate memory for).

I'll give you a chance to attempt this before posting any code to help you out because what you need already exists in the other thread and the rest seems pretty straight forward.

sfuo 111 Practically a Master Poster

Modulos gives the remainder of the two numbers if they were used in division.

Places where I use the mod operator are where I see wrapping. So if I had a problem where I wanted to know what angle a line was making from the center of a cricle, I would probably want it to be from [0-360) and not some larger or smaller angle.

The reason why I used static_cast<int> is because I was just trying to show that it will give an int and not pop out a x.5 (and for some reason you are returning double on your function when you are dealing with ints).

Here are two methods that you can use. One is just a cleaned up version of what you posted (an if with the same condition of the do{}while() can be replaced with just a while()) and a method that uses % for both positive and negative steps.

Cleaned up while() method:

int boundaryWHILE( int pos, int step, int size )
{
    if( step == 0 )
        return pos;

    int fpos = pos + step;

    while( fpos < -(size/2) )
        fpos += size;

    while( fpos > (size/2) )
        fpos -= size;

    return fpos;
}

mod method:

int boundaryMOD( int pos, int step, int size )
{
    if( step == 0 )
        return pos;

    step %= size;

    if( step < 0 )
        step += size;

    return (pos + size/2 + step)%size - size/2;
}

The modulus method can probably be …

sfuo 111 Practically a Master Poster

I don't know what this "sth" is and I don't know what assumptions you are making as far as the size coming in goes, but here is a method you could use.

int boundary( int pos, int step, int size )
{
    return (pos + static_cast<int>(size/2) + step)%size - static_cast<int>(size/2);
}

The assumptions that are being made here are that size will be odd and that the range of values will always be equal in both directions off 0. And that step is going to be positive.

sfuo 111 Practically a Master Poster

You can use strings rather than chars.

If you do not want to read in spaces then you can use cin as your method of input. If you want to include spaces (something like a frist and last name) then you need to use getline(cin, str) for input.

sfuo 111 Practically a Master Poster

I would like to say that I agree with WaltP and that you should start off with learning the language before trying to hop into making a game with graphics. The first game I ever made was black jack in a console window (looking back on it, it was a POS) and I learned loads.

However, another option is to use SDL. I learned from it but quickly switched off to OpenGL to attempt some 3D "games".

Here is the tutorial website I used. This shows you how to setup SDL for Code::Blocks and a few other IDEs.

sfuo 111 Practically a Master Poster

In <windows.h> ERROR is defined as 0. So unless you were to undefine ERROR before your enum you would be writing

enum ERR_CODE { SUCCESS, 0 };

because the preprocessor just does a "find-replace" for ERROR and swaps it with 0.

A quick solution would be to just define SUCCESS as 1 so then ERROR is 0 and SUCCESS is 1. This is backwards to how you wanted it but unless you undefine ERROR or come up with a different name you cant do anything else.

sfuo 111 Practically a Master Poster

Yeah if you wanted to have it work for 2D and 3D points then you could either overload the function to do both 2D and 3D "hardcoded" or you can use a loop to sum all the squares then take a single squareroot at the end.

Example

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

double Distance(vector<double> pt1, vector<double> pt2)
{
    if( pt1.size() != pt2.size() )
        return 0;

    double sum = 0;
    for( unsigned int i = 0; i < pt1.size(); i++ )
        sum += (pt2[i]-pt1[i])*(pt2[i]-pt1[i]);

    return sqrt(sum);
}

int main(int argc, char *argv[])
{
    vector<double> pt1, pt2;
    pt1.push_back(150);
    pt1.push_back(50);
    pt2.push_back(15);
    pt2.push_back(20);

    cout << Distance(pt1, pt2) << endl;
}
sfuo 111 Practically a Master Poster

I kind of see what you are trying to do with the nested for() loops but it is wrong.

For distance I would just make a function that takes in the two coordinates, or this 4 element array, and then just plug it into the formula.

Also in C++ you want to use the cmath library for math and not the math.h C version.

#include <iostream>
#include <cmath>

using namespace std;

double Distance(int x1, int y1, int x2, int y2)
{
    return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}

double Distance( int coords[4] )
{
    return sqrt((coords[2]-coords[0])*(coords[2]-coords[0]) + (coords[3]-coords[1])*(coords[3]-coords[1]));
}

int main(int argc, char *argv[]) {

    int coord[2*2] = {150, 50,
                      15, 20};

    cout << Distance(coord[0], coord[1], coord[2], coord[3]) << endl;
    cout << Distance(coord) << endl;
}
phorce commented: Thank you! :)!!! +4
sfuo 111 Practically a Master Poster

There are a few methods for finding the det of a matrix.

Here is an example for using the minors method.

sfuo 111 Practically a Master Poster

On line 16 you need scanf("%d", &a[n-1]);

It was not working because scanf() takes in a pointer to the variable in which you want to write to.

The reason why you need to write to n-1 is because if you have an array that has a length of 5 the indicies that you should be accessing for that range are 0, 1, 2, 3, 4 (note that you do not access 5).

sfuo 111 Practically a Master Poster

The code that you are using for checking who wins is pretty bulky. If you just treat the hands like 0, 1 and 2 and that higher numbers beat lower numbers with the exception that 0 beats 2 then you can just use the mod operator to wrap around and see who wins.

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
    srand(time(NULL));
    int player, cpu;
    char option;
    int wins = 0, losses = 0, ties = 0;

    char hands[3] = {'r', 'p', 's'};

    while(1)
    {
        cout << "Enter (R)ock, (P)aper, (S)cissors, or (Q)uit:" << endl;
        cin >> option;

        if( tolower(option) == 'r' )
            player = 0;
        else if( tolower(option) == 'p' )
            player = 1;
        else if( tolower(option) == 's' )
            player = 2;
        else if( tolower(option) == 'q' )
            break;
        else
            continue;

        cpu = rand()%3;

        cout << "Player | CPU" << endl;
        cout << hands[player] << "    " << hands[cpu] << endl << endl;


        if( player == cpu )
        {
            cout << "Tie!" << endl;
            ties++;
        }
        else if( player == (cpu+1)%3 )
        {
            cout << "Player wins!" << endl;
            wins++;
        }
        else
        {
            cout << "CPU wins!" << endl;
            losses++;
        }

        cout << "Score:" << endl;
        cout << "w: " << wins << " | l: " << losses << " | t: " << ties << endl << endl;
    }

    return 0;
}

I added in a score keeping feature too.

sfuo 111 Practically a Master Poster

If you use atan2(y,x) it handles divide by zero and what quadrant the angle lies automatically.

sfuo 111 Practically a Master Poster

On line 11 your function prototype says that approximateSqrt() takes no parameters so that is where that error is coming from. To fix it change that line to double approximateSqrt(double);

sfuo 111 Practically a Master Poster

You don't have a display function or an idle function. Not 100% sure if this is the problem since I haven't used glut in a while but from what I remember you need them.

sfuo 111 Practically a Master Poster

The variable ans is initialized but not set.

Right before your for() loop you should write ans = num; otherwise ans will just have a garbage value in it.


EDIT

Or you can change line 7 from cin >> num; to cin >> ans; .

sfuo 111 Practically a Master Poster

Like VernonDozier said, you are declaring 'char c' out of scope but there are also a few other errors within your program.

You are calling the function srand() at the start of the for() loop on each iteration which results in all the characters being the same. The solution to this is to call srand() once either at the start of this function or at the beginning of main() (I would suggest placing it at the start of main()).

The second problem is the range for your rand() function. You had rand() % 26; which will generate a number from 0 to 25 not 0 to 26. So the solution is to just set your maximum to the maximum value in your range + 1.


I did a bit of tweaking and shortened your append section but for the most part it is the same.

Also notice that srand() is not being called here because it should be at the start of main().

string genstring()
{
	string generated_string;
	string stringsize = inputsentance();

	for( unsigned int k = 0; k < stringsize.size(); k++ )
	{
		char c = rand() % 27 + 'A'; //random from "A-["

		if( c == '[' )
			c = ' ';

		generated_string.append(1, c);
	}
	return generated_string;
}
sfuo 111 Practically a Master Poster

If you wanna do a quick n dirty transpose on output just switch your i and j values when printing out. From out[i][j] to out[j][i] will output the transposed matrix assuming that it is a square (#rows = #cols).

If you don't know if #rows = #cols then you do what you are doing now but you must allocate memory for your vector before trying to access it. You can set the size of outtrans by writing

vector< vector<double> > outtrans(out[0].size(), vector<double>(out.size()));

This creates a new 2D vector with the reversed dimensions of "out".

sfuo 111 Practically a Master Poster

For the most part the code is pretty good. You made a few minor errors that would be expected since you are still starting out but you should really work on consistency in indentation since it is harder to read and edit (you will really notice this later on) so you should get into the habit of trying to make your code look nice early on.


I commented in a few places where I made changes.

#include <iostream>
#include <cstdlib> //needed for system() because not all compilers include this header by default

using namespace std;

//the way you are using your functions you can/should have them all return void
void getlist(int[], int&);
void putlist (const int[], int);
void mean_average (const int[], int);
void MinIndex (const int[], int);
void left_rotate (int[], int);

const int MAXSIZE = 50;

int main()
{
	int mylist[MAXSIZE];
	int num_items;

	getlist(mylist, num_items);
	putlist(mylist, num_items);
	MinIndex(mylist, num_items);
	mean_average(mylist, num_items);
	left_rotate(mylist, num_items);

	system ("PAUSE");
	return 0;
}

void getlist(int mylist[], int &num_items)
{
	cout << "Enter the number of Array Elements, Maximum " << MAXSIZE << endl;
	cin >> num_items;

	for( int i = 0; i < num_items; i++ )
	{
		cout << "Enter the next array element: ";
		cin >> mylist[i];
	}
	cout << endl;
}

void putlist(const int mylist[], int num_items)
{
	cout << endl << "Array elements\n";
	for( int i = 0; i < num_items; i++ )
	{
		cout << i << " " << mylist [i] << endl;
	}
}

void …
sfuo 111 Practically a Master Poster

Yeah if you want it to include 0 and be one less than RAND_MAX for your range.

sfuo 111 Practically a Master Poster

rand()%RAND_MAX should generate [0,32767) meaning the number will never be 32767.

If you want it to include 32767 then just use rand()%(RAND_MAX+1).

sfuo 111 Practically a Master Poster

Without actually knowing how it is implemented and by only playing around with these two classes it seems when there is a name conflict (in this case x) the default scope to be used is that of the class that is calling it. When inheriting another class the class that is being inherited is added to the scope of the "inheriter" if there is no conflict.

For example

class B
{
	public:
	int x;
};

class D: public B
{
	public:
	int x;
};

would result in 'D' looking like

class D: public B
{
	public:
	int D::x; //in the default scope so 'D d.x' would look at this
	int B::x; //name conflict so would need to use 'D d.B::x' to access 
};

As for implementing a structure like this in C I would say it is impossible to put two variables with the same name into the same structure since there are no namespaces or 'built-in' inheritance in C. I came across this page and it goes over how to make classes with functions and inheritance in C (I didn't read it that much just scrolled through it).

sfuo 111 Practically a Master Poster

I compiled this with Code::Blocks and Visual Studio and both worked just fine.

sfuo 111 Practically a Master Poster

The issue lies within your function gasket().

On line 34 you are missing an equals sign between point and T, so it should look like

GLPoint point = T[index];

Then when you are adding point.x and t[index] then dividing by 2 you really want to add each component then divide by two. So line 42 and 43 should look like

point.x = (point.x + T[index].x) / 2;
point.y = (point.y + T[index].y) / 2;

Also I'm not sure about you but when I try to compile it gives me a bunch of undefined reference errors about all the OpenGL functions, so at the top I had to put

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
sfuo 111 Practically a Master Poster

It looks like all your errors/problems are in "cdrom.cpp".

In the function CDROM::setName() you have getline(cin, name) being printed out in your cout statement. The function getline() returns *this which is a pointer to the istream object being used (I think, either way this is not what you want). Also you have cin.ignore() being used which is pointless because getline() reads the '\n'. cin.ignore() should be used after reading in a number (int, float, double) because when reading in a number you only read in digits, decimals and signs (+/-), which results in characters typed in after to be left in the input buffer (ie "22char\n" results in "char\n" being left in the input buffer).

The next function, CDROM::setType(), has the exact same problem as CDROM::setName() so get rid of the cin.ignore() and do not output getline().

In CDROM::setCost() you want to clear the input buffer after you input the number because it leaves characters in the buffer, but you do this after you get the input not before. In order to use the line cin.ignore(numeric_limits<streamsize>::max(), '\n'); you need to include <limits> at the top because numeric_limits<streamsize>::max() is defined within it. If you do not clear the input buffer then when this loops for the next CDROM input you will not see text pop up until you type in something.

Here is what I did to correct the errors.

void CDROM::setName()
{
    cout << "Please enter name : ";
    getline(cin, name);
}

void CDROM::setType()
// …
sfuo 111 Practically a Master Poster

When you put #included <cmath> (notice they are < brackets not " quotes) you got a bunch of errors. If you read the errors they just say that it doesn't know what datatype you are trying to pass into the ToString() function. The work around to for this is to cast the result into a double or something (I tried long double and it didnt work).

So just change the last line of your calcu_Click() function to

this->rp->Text=Convert::ToString((double)pow(ni,nii));

Edit: make sure you include cmath at the top of Form1.h but under the #pragma once

sfuo 111 Practically a Master Poster

Honestly I'd have to see some source code before I can tell you how to fix it. The code that I have from the default VC++ template is really bare bone.

So if you could zip up your project files (do not need all the .obj files and other stuff that is made when compiling) and I'll take a look at it.

sfuo 111 Practically a Master Poster

I have never made a Windows Form Application before but I just made one out of the template and threw #include <cmath> (you should use cmath not math.h in C++) at the top and it compiled without a problem, since as I suspected just C++ with a big library attached to it.

So what you can do is just go to the source file with all the functions you are trying to use the cmath functions in and include cmath at the top of it.

sfuo 111 Practically a Master Poster

This is one of the most basic examples I can come up with that includes exactly what you asked.

#include <iostream>
using namespace std;

class ClassA
{
	int a, b;

	public:
	ClassA(){}; //need a default constructor
	ClassA(int _a, int _b)
	{
		a = _a;
		b = _b;
	}
};

class ClassB
{
	int x, y, z;
	ClassA a1;

	public:
	ClassB(){}; //not needed in this but should have one
	ClassB(int _x, int _y, ClassA _a1, int _z)
	{
		x = _x;
		y = _y;
		a1 = _a1;
		z = _z;
	}
};

int main()
{
	ClassA A(1, 2);
	ClassB B(4, 5, A, 6);


	return 0;
}
sfuo 111 Practically a Master Poster

Yep. Unless you are on windows then you can use system("PAUSE"); but thats kind of frowned upon.

sfuo 111 Practically a Master Poster

return 0 has nothing to do with pausing the program, its just a value that gets returned to the program that called it (since main is just a function that returns an int).

sfuo 111 Practically a Master Poster

You can't. If your compiler supports it then you can have a pause when it is ran through the compiler but no program runs and pauses at the end without being forced to.

sfuo 111 Practically a Master Poster

One big thing you have to understand is that a function (ie main()) is not a class.

Classes hold variables and functions which can be accessed/used via the "dot" (.) operator.

Here is an example of an Event_Time class that prints out the current date and time when you call the function CurrentTime().

#include <iostream>
#include <ctime>

using namespace std;

class Event_Time
{
	time_t current_seconds;
	tm *timeinfo;
	char buffer[80];

	public:

	void CurrentTime()
	{
		current_seconds = time(NULL);
		timeinfo = localtime(&current_seconds);
		strftime( buffer, 80, "Event Date: %x", timeinfo );
		cout << buffer << endl;
		strftime( buffer, 80, "Event Time: %X %Z", timeinfo );
		cout << buffer << endl;
	}
};

int main()
{
	Event_Time event; //creates a new event

	event.CurrentTime(); //displays the current time

	return 0;
}

Notice how there is no assignment done outside of functions within the class (if you want to declare and initialize at the same time outside of functions within the class then it must be a static constant variable (ie static const int x = 5 ).

If you want to initialize variables right when the object is made then you either call a function that assigns or you define a constructor for the class.

Here is an example using a constructor.

#include <iostream>

using namespace std;

class myClass
{
	int myVariable;


	public:

	myClass() //Constructor. Notice that it does not have a return type. This will replace the default constructor.
	{
		myVariable = 5;
	}

	myClass( int in ) //This …
sfuo 111 Practically a Master Poster

I don't see the point in him posting that at all then. He is just showing someone, that doesn't know what they are doing, code that doesn't work.

@Adam Ma
I would highly recommend you go over this tutoral. I learned C++ from here and I use the reference section all the time.

sfuo 111 Practically a Master Poster

This took a bit more than 30 secs but it isn't full of errors and uses whitespace so you can actually see what is going on.

#include <iostream>

using namespace std;

int main()
{
	int num;

	cout << "please enter a number" << endl;
	cin >> num;
	if( num > 0 )
	{
		for( int i = 0; i < i; i++ )
		{
			cout << i << endl;
		}
	}
	else
	{
		cout << "number is less than or equal to 0" << endl;
	}

	return 0;
}
sfuo 111 Practically a Master Poster

You can try running what I have zipped up but my last guess as to what might be wrong is the fact that you have msvcrtd.lib and mfcs80ud.lib in 'Ignore Specific Default Libraries'. When I put those in I got errors but not the same ones as you.

sfuo 111 Practically a Master Poster

See attached image

The file that was inside the zip doesn't do anything. I removed all my linked libraries and tested to see what ones I need and don't need and there are three that you need in order to compile the code you posted.

kernel32.lib
user32.lib
gdi32.lib

You can check the box 'Inherit from parent or project defaults' to load in all the libraries in the lower section of the pop up box of the screen shot below.