William Hemsworth 1,339 Posting Virtuoso

That wont work, you fergot to add curly brackets for the if statement.

William Hemsworth 1,339 Posting Virtuoso

It seems a bit pointless to have double the amount of cases than you actually need.

//when user inputs a char..
    char classChoice;
    cin>> classChoice;


    switch(tolower(classChoice))
    {
         case 'w':
                       cPtr = new Character(/*Warrior stats here*/);
                       break;
         case 'm':
                       cPtr = new Character(/*Mage stats here*/);
                       break;
          default:
                       cout << "Improper selection" << endl;
                       break;

    }
William Hemsworth 1,339 Posting Virtuoso

Try this:

#include<windows.h>
#include<iostream>

#define DebugMessage(str)	OutputDebugString(str)

int main() {
	DebugMessage("Hello");
	std::cin.ignore();
	return 0;
}
William Hemsworth 1,339 Posting Virtuoso

The reason you got 46 twice there isn't because the random number happends to be the same, its because you are printing the same variable twice without modifying it. If you want to make it so each number can only come up once, you have to make an array for the numbers to go into it and then check it to see if it has already been added.

William Hemsworth 1,339 Posting Virtuoso

What about the datatype __int8, is that guaranteed to be 8-bit? Because it seems to act exactly as a char and would be abit misleading otherwise.

William Hemsworth 1,339 Posting Virtuoso

At least somebody understood me :)

William Hemsworth 1,339 Posting Virtuoso

Good point, I was just saying base 26 because theres 26 letters in the alphabet, when I did this I just passed the length of the string containing the alphabet values so I wasn't aware what base it actually was. Thanks for the correction :)

William Hemsworth 1,339 Posting Virtuoso

Win32 programming definetly requires a a bit of experience in C++, but if you get good at C++, you dont have to worry about learning the Win32 API, its easy. The hardest part I would say is just remembering all the function and macro names because theres just so many :-/
In the Win32 API the switch statement is very commonly used, and its the basic stuff like that which you really need to know.

William Hemsworth 1,339 Posting Virtuoso

If I showed you my code you would almost certainly not understand it if you are not able to even make a start on it. My advice is, break it up into smaller sections, and do one thing at a time. If you decide to do it the way I suggested you could start with the following things:

- Make a function to convert the base 26 value into a base 10 value with a data type of unsigned __int64, the prototypes should look something like this unsigned __int64 fromBase26(char *val) - Make a function to convert the value to base 26 with the prototype similar to this void toBase26(char *lpTarget, unsigned __int64 val) With those two functions the problem becomes simple, just simply convert the two base 26 numbers to base 10 (unsigned __int64) values. Then you make a third variable defined as unsigned __int64 answer = num1 + num2 and then convert is back to base 26 and display it.

William Hemsworth 1,339 Posting Virtuoso

OK then.. Now this is just completely off topic. :icon_wink:

William Hemsworth 1,339 Posting Virtuoso

Hmm, now that we are recommending books, heres the first book I ever read for C++, at about the age of 12 ^.^.
http://www.amazon.com/Beginners-Guide-Second-Guides-McGraw-Hill/dp/0072232153
But there has already been an entire thread for C++ books here.
http://www.daniweb.com/forums/thread70096.html

William Hemsworth 1,339 Posting Virtuoso

Im not the person to ask for that, I have never worked with linux before.

William Hemsworth 1,339 Posting Virtuoso

That tutorial might be to advanced for your level, so stick with console applications for a while before trying the Win32 API or you might get really confused :confused:

William Hemsworth 1,339 Posting Virtuoso

Yes

William Hemsworth 1,339 Posting Virtuoso

You can make more than just console application using C++, you can use the Win32 API to create visual application. Try googling:
C++ Win32 API or
C++ MFC

William Hemsworth 1,339 Posting Virtuoso

You're not very quick, are you?

I see what you mean :D

So your telling me what is being displayed on my windows screen is the output of a C++ program?

Most probably.

William Hemsworth 1,339 Posting Virtuoso

Try this, I haven't read it yet.. but its supposed to be good. :icon_mrgreen:
http://beej.us/guide/bgnet/

William Hemsworth 1,339 Posting Virtuoso

Because a local object will destruct at the end of the code block / function and therefore you will be returning an invalid reference.

William Hemsworth 1,339 Posting Virtuoso

Im not sure why, but I had a go at making this and succeeded but im not going to give you the solution to it, so you can at least have a go at it yourself. But I will tell you how I managed it.

  1. I made two function, one that converts the base 26 number into a base 10 decimal number, and one that converts a base 10 number into a base 26 number.
  2. I Used the first function to get the decimal value of the two numbers, and then added them togeather using the data type unsigned __int64 .
  3. Finally I converted the base 10 answer into a base 26 integer.

This worked for me but may not work with extremely large numbers
(numbers larger than unsigned __int64).
But there are many different ways to manage this, so this is only one solution and probably not the best.

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Well, I compiled the code and it worked perfectly for me, so mabey its something to do with your compiler settings.

William Hemsworth 1,339 Posting Virtuoso

You are missing the null terminator at the end, but that shoulden't explain why its outputting the address of t . The correct way to do it would be like this:

char trig [10] = "cos(50)"; //declare and assign the char array "trig"
char t [4]; //declare char array t to store the "cos" part of the trig array

t[0] = trig[0];
t[1] = trig[1];
t[2] = trig[2];
t[3] = '\0';

Try that and see if it works

William Hemsworth 1,339 Posting Virtuoso

Ok, but I get the feeling he would be more interested in using graphics considering we are very similar ages (14-15) and seems to enjoy messing around and making games, quite like me :P . I especially think he would enjoy directX if he were a little more experienced in programming, even though it might be abit advanced for him (im also having a bit of a hard time learning it). But like you sead Everyone has a different idea of what's fun, so I might be completely wrong :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

This is what you do when your bored ?!
I suggest you try learning the Win32 API to be able to make proper window applications, and then mabey move on to MFC when you get the hang of that. From there you should be able to make basic games / animation. Anything is more fun than this ^.^

Start with this tutorial
http://www.winprog.org/tutorial/

Prabakar commented: Great link +1
William Hemsworth 1,339 Posting Virtuoso

Isn't it just:

binaryImage->Save("binaryImage.bmp");

???

William Hemsworth 1,339 Posting Virtuoso

I cant even see the quick reply box because you posted so much code...

William Hemsworth 1,339 Posting Virtuoso

Yes , If you are using Windows As An OS.

YOU CAN TRY

system(cls);

To Clear the whole thing up and then a printer function added in.

I guess you ment

system("cls")
William Hemsworth 1,339 Posting Virtuoso

I suggest you get yourself a good book on C++ because it looks like you have no idea what your doing in some places :icon_neutral:
You should also learn to format your code better, you have about 10 empty lines near the end and your indentation is messed up.

I have recommended this book a few times because it is very easy to follow and teaches you good techniques on programming.

C++ A Beginner's Guide Second Edition by Herbert Schildt.
http://www.amazon.com/Beginners-Guide-Second-Guides-McGraw-Hill/dp/0072232153


If you decide not to get that, you can also read a decent tutorial, like this one.
http://www.cplusplus.com/doc/tutorial/program_structure.html

Hope this helps.

William Hemsworth 1,339 Posting Virtuoso

165 = 10100101

William Hemsworth 1,339 Posting Virtuoso

In addition to what niek_e sead, you could make things easier by using some windows macros.

#include<windows.h>
#include<iostream>
using namespace std;

int main(){
    /*max 65535 (= sizeof(unsigned int) /2) */
    unsigned int i = 2222; 
    unsigned int j = 1111;
    unsigned int combined = MAKELONG(i, j);
    cout << LOWORD(combined) << '\n';
    cout << HIWORD(combined);
    cin.ignore();
    return 0;
}
William Hemsworth 1,339 Posting Virtuoso

Good point!, he got me thicking strangely. But you cannot compare two arrays using the == operator.
So the correct way would be:

if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)&&help != 1)
William Hemsworth 1,339 Posting Virtuoso

On line 11 and 19 you cannot compare a char string using the == operator. Instead use strcmp http://www.cplusplus.com/reference/clibrary/cstring/strcmp.html.

Line 11:

if((argv[i] == "-h" | argv[i] == "--help" ) && help != 1)

Should be:

if ((strcmp(argv[i], "-h") == 0) | (strcmp(argv[i], "--help") == 0)&&help != 1)

Do the same thing with line 19 and see if it works then.

You could also use std::string and then use the == operator to compare it with another string.

FreeFull commented: Helpful +2
William Hemsworth 1,339 Posting Virtuoso

Please Use code tags, It makes reading it so much easier :)

William Hemsworth 1,339 Posting Virtuoso

Wow, I cant believe I couldnt find that online myself. Thanks its exactly what I needed.

Yep, I dont even think Ancient Dragon looked online for that site :icon_wink:

But try this tutorial, I think it will help you.
http://winprog.org/tutorial/start.html

William Hemsworth 1,339 Posting Virtuoso

You could also make it so you dont have to manually set the array size like this:
(Assuming your not dynamically allocating the array)

int nums[] = {324, 5462, 2};
int average = 0;

short arraySize = sizeof(nums) / sizeof(*nums);

for (short i = 0; i < arraySize; i++)
	average += nums[i];

average /= arraySize;

cout << average;
William Hemsworth 1,339 Posting Virtuoso

Set yourself a challenge like making a function to determine wheather or not a number is a prime. If you get stuck, use google to figure out your problem. :icon_lol:

William Hemsworth 1,339 Posting Virtuoso

Nice work :), This looks like a good tutorial and Ive never really managed to get the hang of asm, Thanks!

William Hemsworth 1,339 Posting Virtuoso

This might not help with your exact problem, but don't use void main() as Salem's avatar will clearly show you :)

William Hemsworth 1,339 Posting Virtuoso

You will have to create another bitmap and use BitBlt to copy the data to it, more info here.
http://msdn.microsoft.com/en-us/library/aa930997.aspx

William Hemsworth 1,339 Posting Virtuoso

What ?!, did you read neik_e's post.. :angry:
Nobody's going to do your work for you..

William Hemsworth 1,339 Posting Virtuoso

i dont know how to make array on a function...

:icon_idea: Ever heard of google?

William Hemsworth 1,339 Posting Virtuoso

It would have been much more practical if you had attached the many pages of code...
But just a few mistakes / tips:

  1. Dont use system("pause") : http://www.gidnetwork.com/b-61.html
  2. In your switch statement switch (move) you have including double the amount of cases than you actually need, just define it like this switch (tolower(move)) and have each case with just a lower case char.
  3. Format your code better!
William Hemsworth 1,339 Posting Virtuoso

Well, dynamically allocating space is much slower than stack and the life of a dynamic variable is dependant on when you decide to delete it, however stack variables are deleted at the end of the code block.

William Hemsworth 1,339 Posting Virtuoso

Please check the date that this thread was created...

William Hemsworth 1,339 Posting Virtuoso

Well, the way I did it was to first check how the numbers as integers compared and if they are equal, then you move on to the numbers after the decimal point, and compare each one of them until one of the numbers are different.

William Hemsworth 1,339 Posting Virtuoso

Ok then, this makes stuff slightly harder. I didn't really understand that way you tried to do it so I went ahead and made one myself. Theres most probably an easier way to do this, but heres my attempt at it.

#include <iostream>
#include <string>

using namespace std;

int compareFloats(string str1, string str2) {
	int dp1, dp2;
	int iNum1, iNum2;

	for (int i = 0; i < (int) str1.length(); i++) {
		if (str1[i] == '.') {
			dp1 = i;
		}
	}

	for (int i = 0; i < (int) str2.length(); i++) {
		if (str2[i] == '.') {
			dp2 = i;
		}
	}

	iNum1 = atoi(str1.substr(0, dp1).c_str());
	iNum2 = atoi(str2.substr(0, dp2).c_str());

	if (iNum1 < iNum2) return -1;
	if (iNum1 > iNum2) return  1;

	// Check after point
	for (int i = dp1 + 1,
		     j = dp2 + 1;
			 i < (int) str1.length() && j < (int) str2.length(); i++) {
				 if (str1[i] < str2[j]) return -1;
				 if (str1[i] > str2[j]) return  1;
	}

	return 0; // Equal
}

int main(void)
{
	int n;
	string numz[200];

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> numz[i];
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			int c = compareFloats(numz[j], numz[j+1]);
			if (c == 0) continue;
			if (c == 1) numz[j].swap(numz[j+1]);
		}
	}

	for (int i = 0; i < n; i++) {
		 cout << numz[i] << ' ';
	} …
William Hemsworth 1,339 Posting Virtuoso

You have left alot of space between lines, and you shouldent use system("pause") (http://www.gidnetwork.com/b-61.html)

William Hemsworth 1,339 Posting Virtuoso

If all your trying to do is sort int's / floats you are doing it the hard way, all you have to do is convert each string you input to a float and then sort them. So you can delete the other two functions (lrg, posd). Something thing you should aim to improve is your formatting, some parts of the code were very difficult to understand. And finally, not the biggest mistake in the world but you shoulden't use system("pause"), reason here: http://www.gidnetwork.com/b-61.html

But what I have done is converted the strings to floats by using atof and then sorted them. As atof can only handle plain char* strings you have to convert them by using string::c_str().

#include <iostream>
#include <string>

using namespace std;
   
int main(void)
{
	int n;
	string numz[200];

	cin >> n;

	for (int i = 0; i < n; i++) {
		 cin >> numz[i];
	}

	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			if (atof(numz[j].c_str()) > atof(numz[j+1].c_str())) {
				numz[j].swap(numz[j+1]);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		 cout << numz[i] << ' ';
	}

	//cout << numz[0];

	// Pause the better way
	cin.ignore();
	cin.ignore();

	return 0;
}

I have colored the main changes I made, hope this helps.

William Hemsworth 1,339 Posting Virtuoso

Because you havent formatted your code very well, you missed out a curly bracket during your switch statement. I have formatted and made the following corrections for you:

/*------------------------------------------------------------------
* Assignment 7: FIRST LINKED LIST ASSIGNMENT.
*Worth: 50 points
*Made by: Samuel Georgeo (max11)
create
an in-memory SERIALLY linked-list database program which
displays a menu screen.
-------------------------------------------------------------------*/

#include <stdio.h>
#include <iostream>
#include "/var2/local/include/getch.h"
using namespace std ;
/*-----------------------------------------------------
* MAIN PROGRAM STARTS HERE
-----------------------------------------------------*/
int main(int argc, char *argv[1])
{
	char  b;
	while(1)
	{
		putchar('\n') ;
		puts("\t\te) Enter a new agent");
		puts("\t\tl) List agents in file");
		puts("\t\tn) Next Struct in List");
		puts("\t\tp) Prev Struct in List");
		puts("\t\tq) Quit program");

		if (phere)  // avoid segfault for nonexistant record
		phere->print_rec() ;

		putchar('\n') ;
		b = getch();
		switch(b)
		{
			case 'e':
				if(!p) {
					p = new prs;
					if (!p) exit(-1)
					p > next = p > prev = p;
					edit_rec (p);
				} else {
					phere = p > prev;
					pnew = new prs;
					if (!pnew) exit(-1)
					p > prev = pnew;
					pnew > next = p;
					phere > next
				} // You missed this out..
				break;

			case 'l':
				puts("you typed l") ;
				break;
			case 'n':
				phere= phere->getNext() ;
				break;
			case 'p':
				phere= phere->getFrom();
				break;
			case 'q':
				puts("you typed q") ;
				return 0 ;
				break;
		};  // switch case b
	};
	deletelist (head);
}// main
William Hemsworth 1,339 Posting Virtuoso

rocks are boring :icon_cheesygrin:

William Hemsworth 1,339 Posting Virtuoso

3 Threads posting the same problem.. ? Doesn't anybody try to do their homework by themselves anymore ?? You could have all helped eachother with it and you would figured out the problem in no time. :P

Salem commented: You could bash all their heads together, and still not get a spark of intelligence ;) +17