NathanOliver 429 Veteran Poster Featured Poster

okay so that function shouldn't be part of the student class. you should have a print function in your class that prints the student information. then you create your print records function to accept a student array and then call the print function for each student in the array.

NathanOliver 429 Veteran Poster Featured Poster

change your do...while loops to just a while loop.

do
	{
		cout<<endl<<"Invalid. User Id must be at least 6 digits. Retry:";
		cin.getline(userId, 20);

		length = (long)strlen(userId);
	}while(user_ID_length(userId, length)==false);

// to

while(user_ID_length(userId, length)==false)
{
        cout<<endl<<"Invalid. User Id must be at least 6 digits. Retry:";
	cin.getline(userId, 20);

	length = (long)strlen(userId);
}
NathanOliver 429 Veteran Poster Featured Poster

are you sure that function has to be part of your student class or is that a separate function to be called in main?

NathanOliver 429 Veteran Poster Featured Poster

first for your strncmp you need to make pass the string email_address as a char*. to do this you need to use the c_str() method

strncpy(userId, email_address.c_str(), 9);

second isalpha actually takes an int so you can only use a single character not a whole string so you would need to write a for loop to go through each element of the array and call isalpha on that.

third you are using do..while loops. i would use while loops instead because as it stands you will run the loop at lease once even if your input is correct. also i believe you are calling functions in you while part of the loop but there is no (). if

}while(user_ID_length==false);

// did you mean?

}while(user_ID_length(userId, length) == false);

if you have any more problems please post them and i would be happy to help

The ICE Man commented: Good Points, well done :) +0
jonsca commented: Agreed +4
NathanOliver 429 Veteran Poster Featured Poster

Hey all

I have been writing my own implementation of a BigInt class and I think I have most of it down. I am using a vector<int> container for my number. I'm curious to what you guys think about. This is my first program using 1000+ lines of code. Please fell free to point out anything I'm doing wrong or if any of it is confusing. I'm including the code as attachments as well so you don't have to copy and paste it. At present I have 12 warnings from my compiler possible loss of data when converting from size_t to int and I'm not sure yet how I want to fix that. Any suggestions on that would be helpful.

Thanks
Nathan Oliver

NumberClass.h

//**************************************************************************//
//  This program is free software: you can redistribute it and/or modify    //
//  it under the terms of the GNU General Public License as published by    //
//  the Free Software Foundation, either version 3 of the License, or       //
//  (at your option) any later version.                                     //
//                                                                          //
//  This program is distributed in the hope that it will be useful,         //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//  GNU General Public License for more details.                            //
//                                                                          //
//  You should have received a copy of the GNU General Public License       //
//  along with this program.  If not, …
NathanOliver 429 Veteran Poster Featured Poster

is there any more to the lnk1120 error message or was that all the compiler said? also please use code tags

NathanOliver 429 Veteran Poster Featured Poster

i would go a different way. i would use the first code that you posted and have each monster be its own instance of the monster class. then i would either have a file with all the different monsters and load the array with that or just hard code it.

NathanOliver 429 Veteran Poster Featured Poster

the getline function uses a delimiter in when determining when to end the input. the default is '\n' but you can change it to whatever you want.

string getLine(string line)
{
	getline(cin, line, '-');
	return line;
}
NathanOliver 429 Veteran Poster Featured Poster

yes you can acces the class as long as you pass it. a simple way to demonstrate this would be

bool AttackMonster(monsters * monster, int indexOfMonster);

int main()
{
	bool result = false;
	int index = 0;
	monsters monter[325];
	// load the array with all thge differnt monster types
	LoadMonsters(monster);
	// later on they get attacked so call attack function
	result = AttackMonster(monster, index)
	// do more stuff
	return 0;
}

hope I'm making sense here.

NathanOliver 429 Veteran Poster Featured Poster

well you can use getline with '-' as the delimiter so you don't need to check for the negative. also your function is returning void. are you sure you want to do that? I believe you would want to return the string to the function that called this function.

NathanOliver 429 Veteran Poster Featured Poster

could you please post the code that uses this line.

NathanOliver 429 Veteran Poster Featured Poster

You are mixing input types. After your call to cin >> tmp you need to clear the input buffer. You can use cin.ignore() for this. If that does not work narue has a good sticky thread on how to clear the input buffer that is very informative

NathanOliver 429 Veteran Poster Featured Poster

i would try changing this

LList::LList() {
 this->size = 0;
}

// to
LList::LList()
{
       size = 0;
}

// and

int LList::getsize() {
 return this->size;
}

// to

int LList::getsize()
{
       return size;
}
NathanOliver 429 Veteran Poster Featured Poster

the garbage you are getting is because you declared the array to have 20 elements but you are only filling 6 of them. the rest are uninitialized. you could use a vector in this case and that will fix having to know the size because it can re size itself to hold just the data you need. if that's not an option then you could write a second loop in your input function that will start of where you ended filling the array from the file and make the value 0. then in your output function you could put an if statement in your loop to test if the data in index i is equal to 0. if it is then skip it.

NathanOliver 429 Veteran Poster Featured Poster

do you know about the c_str() member function of string? if not it returns a const char * that contains the string. this can be used to pass into functions that only take a char * as a parameter. if you put this together with what Ancient Dragon said you should be able to figure it out.

NathanOliver 429 Veteran Poster Featured Poster

you may also have to add a '\' in between the dir and the file name unless the person enters the dir with a slash at the end

NathanOliver 429 Veteran Poster Featured Poster

if you are seperating the whole part and decimal part then i would make your routine for getting the number into its own function and then in main parse through the string untill you hit the '-' then save that substring as your whole part and the rest will be your decimal part. the tricky part is taking to ints and making a decimal. for that i would use 3 function calls. first i would call itoa on both the whole part and decimal part. then combine both of those strings with a decimal point in bettwen them. then i woulld call strtodnvert the decimal string into a float.

NathanOliver 429 Veteran Poster Featured Poster

okay that i believe is my problem i should not modify my data in the Number object but return a number object which is the sum of the 2 objects. thanks for the help guys.

NathanOliver 429 Veteran Poster Featured Poster

if i were to make my function const then i would need to create a object of my number class in my function and then return that since in my function i am returning a Number & ?

NathanOliver 429 Veteran Poster Featured Poster

Since you are reading from a file you need #include <fstream> also I would use an ifstream object such as

ifstream& operator>>(ifstream &in, ArrayIntStorage &A)
NathanOliver 429 Veteran Poster Featured Poster

Hey All

I am testing myself with making a big number class. Right now I'm just working with integers but I hope to expand it to floats as well. I am using a vector of integers for the container and i have run into a problem with my addition routine. I'm testing to see if one number is a negative or not and then calling the appropriate minus function but I am getting an error when trying to pass the this pointer to the function. The error I'm getting is:
error C2662: 'Number::operator -' : cannot convert 'this' pointer from 'const Number' to 'Number &'

here is my code that i have so far

Number.h

// inclusion guarding
#ifndef NUMBERCLASS_H
#define NUMBERCLASS_H

#include <string>
#include <vector>

class Number
{
public:
	// constructors
	Number();
	Number(int);
	Number(unsigned int);
	Number(char *);
	Number(std::string);

	// destructor
	~Number() {};

	// get functions
	int GetNumberAsInt();			// return as a int if possible otherwise returns 0 and flags error
	std::string GetNumber();
	bool GetSign();					// reuturns true if negative
	bool GetToBig();				// returns true if GetNumberAsInt fails
	
	// math operators
	Number & operator=(const Number &);
	Number & operator+(const Number &);
	Number & operator-(const Number &);

private:
	// private functions
	char* makeInt(char *);
	// private data
	std::vector<int> data;
	int length;
	bool sign;
	bool toBig;
};

#endif
Number.cpp operator+ function

Number & Number::operator +(const Number & number)
{
	int carry = 0;
	int size = 0;
	if (sign && !number.sign)
	{
		return number.operator -(*this);  // this …
NathanOliver 429 Veteran Poster Featured Poster

here is a good link to start with. http://www.daniweb.com/forums/announcement8-2.html

NathanOliver 429 Veteran Poster Featured Poster

do you have any code written already?

NathanOliver 429 Veteran Poster Featured Poster

your while loop isn't working like you think it is i believe. lines 50-61 should be in the while loop and you have them outside it.

NathanOliver 429 Veteran Poster Featured Poster

2 things im seeing off the top is in your readin function after reading in the file data you delete the data in temp and than you delete the data in pc so you do all the work and then delete it all. second your printing function is named printf which is a function in C/C++ for printing data. does your compiler complain about that at all?

NathanOliver 429 Veteran Poster Featured Poster

well if you want a pointer then i believe the syntax would be

faculty * foo = new facilty;
foo->mod[0].st[0].name;

also please you code tags

NathanOliver 429 Veteran Poster Featured Poster

your check if either player has more than the points needed to win is not inside your do while loop. it is only checked before you enter the loop and then you go on forever.

NathanOliver 429 Veteran Poster Featured Poster

i would suggest purchasing a new PSU. 500+ watts should be fine

NathanOliver 429 Veteran Poster Featured Poster

in your if statement when you are outputting your picture of the hanging man you are using a \. with c++ that is an escape character and is used for special purposes line \n for newline. in order to output a single \ to the screen you would need cout << "\\"; .

NathanOliver 429 Veteran Poster Featured Poster

Please refrain from name calling. Salem is a great poster and has some very good advice. you did not post any code or say what this is for so even i though it was asking for homework help. it is best to clearly state what is going on becuase we have no information to go on besides what you have posted.

with that siad i would suggest 2 loops. since you could have multiple's of the same number as a factor. the first loop would run through each digit and the second loop would divide the number as many times as it can by that number. a for loop and a while loop would probably work great.

a good example is the number 8. its factors are 2-2-2 but with your code as above you would get 2-4 which is not correct. my approach would test 2 multiply times and give as an output 2-2-2.

NathanOliver 429 Veteran Poster Featured Poster

@ ookamioni The problem OP is having is he is trying to make a win32 app work as a win32 console. In a console you generally have int main() not WinMain(). He is not missing a ";" anywhere.

NathanOliver 429 Veteran Poster Featured Poster

good news is that if you have to write it in a switch statement you can use the drop through method eg

switch (score)
case 99:
case 98:
// so on
case 90:
       //display info
       break;
case 89:
case 88:
// so on
case 80:
       //display info
       break;
case 79:
case 78:
// unfortunatly this will have to go to 50
case 50:
       //display info
       break;
default:
       // display info
}

its still a lot of writing but at least you wont have to write code for each case.

NathanOliver 429 Veteran Poster Featured Poster

so if you have the string "hello" and the string "loot" it would become "helloot" since the ending "lo" of hello and the beginning "lo" of loot are the same? and "helloeDelhi" hase no over lap so it isnt truncated correct?

NathanOliver 429 Veteran Poster Featured Poster

In your second if statement you are saying if (num < die) . what would happen if I guessed 5 and the die was 2? A better way would be to do if (num != die) .

NathanOliver 429 Veteran Poster Featured Poster

im not seeing a #include <iostream> anywhere.

NathanOliver 429 Veteran Poster Featured Poster

You need to use srand() to seed rand before you use it. For a game like yours i would use srand((unsigned)time(0)); . You will need to use #include <ctime> in your code to do this.

NathanOliver 429 Veteran Poster Featured Poster

What Fbody said. The variables were already declared in the function declaration so when you re defined them the became garbage and were giving you a incorrect answer. Also your formula for calculating the average is flawed.

NathanOliver 429 Veteran Poster Featured Poster

Look at line 70. Notice anything particular about it? Also line 98 is wrong. Your instructions say to calculate the average of the 3 highest scores to the nearest integer. Does a double qualify as an integer? These are some things for you to look at. Remember it is better to start small and debug constantly then to write the whole program and hope it works.

NathanOliver 429 Veteran Poster Featured Poster

Here is a good link for you. http://www.cppreference.com/wiki/stl/algorithm/transform If you cant figure it out still let me know.

NathanOliver 429 Veteran Poster Featured Poster

just use an if statement and if counter is equal to zero use setprecision 0 for your variables.

NathanOliver 429 Veteran Poster Featured Poster

Could you please post your error meesages. Also on line 43 in your do_add() function you are doing sum = num1 + num2; You can not do something like this since they are arrays. You would have to write a function to step through the array and add the numbers together at the index and then carry over into the next larger index. this also applies to your other functions.

NathanOliver 429 Veteran Poster Featured Poster

i striped down your function just to walk it through my debugger and i had to change char ch; to unsigned char ch; in order to get it to work. what was happening was it was using a signed char which has a max value of 128 or DEL. so it was rolling over into the negatives and messing up the end result. i would give it a try and see what happens

NathanOliver 429 Veteran Poster Featured Poster

where are you outputting the data to the file? i have never seen it done with using the iterator normally in the while loop you should have a line like

// in while loop
fout << v1[i] << "\n";
i++;
NathanOliver 429 Veteran Poster Featured Poster

after optimization the code for my strlen function is now

?strlen@@YAHPBD@Z PROC					; strlen

; 12   :        int size = 0;

	xor	eax, eax
$LL2@strlen:

; 13   :        while (*str++)
; 14   :               size++;

	add	eax, 1
	cmp	BYTE PTR $SG-5[eax], 0
	jne	SHORT $LL2@strlen

; 15   :        return size;
; 16   : }

	ret	0
?strlen@@YAHPBD@Z ENDP					; strlen
NathanOliver 429 Veteran Poster Featured Poster

Thanks Vernon for the link it was very insightful. Also I found out how to output the code in assembly to check it and my code is much longer. I think I might have to play with my optimization settings. here it is just FYI

// driver.cpp
int strlen(const char * str)
{
       int size = 0;
       while (*str++)
              size++;
       return size;
}

and

//driver.asm
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.762 

	TITLE	c:\Documents and Settings\Nathan\My Documents\Visual Studio 2005\Projects\daniweb\daniweb\Driver.cpp
	.686P
	.XMM
	include listing.inc
	.model	flat

INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES

PUBLIC	?strlen@@YAHPBD@Z				; strlen
EXTRN	__RTC_Shutdown:PROC
EXTRN	__RTC_InitBase:PROC
;	COMDAT rtc$TMZ
; File c:\documents and settings\nathan\my documents\visual studio 2005\projects\daniweb\daniweb\driver.cpp
rtc$TMZ	SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ	ENDS
;	COMDAT rtc$IMZ
rtc$IMZ	SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
; Function compile flags: /Odtp /RTCsu /ZI
rtc$IMZ	ENDS
;	COMDAT ?strlen@@YAHPBD@Z
_TEXT	SEGMENT
tv65 = -205						; size = 1
_size$ = -8						; size = 4
_str$ = 8						; size = 4
?strlen@@YAHPBD@Z PROC					; strlen, COMDAT

; 11   : {

	push	ebp
	mov	ebp, esp
	sub	esp, 208				; 000000d0H
	push	ebx
	push	esi
	push	edi
	lea	edi, DWORD PTR [ebp-208]
	mov	ecx, 52					; 00000034H
	mov	eax, -858993460				; ccccccccH
	rep stosd

; 12   :        int size = 0;

	mov	DWORD PTR _size$[ebp], 0
$LN2@strlen:

; 13   :        while (*str++)

	mov	eax, DWORD PTR _str$[ebp]
	mov	cl, BYTE PTR [eax]
	mov	BYTE PTR tv65[ebp], cl
	mov	edx, DWORD PTR _str$[ebp]
	add	edx, 1
	mov	DWORD PTR _str$[ebp], …
NathanOliver 429 Veteran Poster Featured Poster

according to my MSDN you should use srand((unsigned)time(0));

NathanOliver 429 Veteran Poster Featured Poster

I'm using MSVC++ 2005 is there a way to see the code for this function in assembly to see if it does convert it to a scansb instruction?

NathanOliver 429 Veteran Poster Featured Poster

ah yes I forgot to increment the pointer as well. so just drop the double ! and the incrementation would be the basic workings right?

int strlen(const char * str)
{
       int size = 0;
       while (*str++)
              size++;
       return size;
}
NathanOliver 429 Veteran Poster Featured Poster

would the workings of strlen() be something like this?

int strlen(const char * str)
{
       int size = 0;
       while (!!*str)
              size++;
       return size;
}

any feedback would be appreciated. also i have learned that !! will convert a value to an actual bool eg. !!104 = 1

NathanOliver 429 Veteran Poster Featured Poster

you would need to reset i to zero and then assign the return to s2 and increment i after each time.