hag++ 24 Junior Poster

Hi All,

I have been programming for a while, currently a junior CS student. Programming has always felt very natural to me and I pick up new concepts quickly and I generally retain most of what I learn. However, when it comes to converting between Dec/Bin/Hex as well as performing bitwise operations, I have never really been able to retain the process. Also, the problem is that every programming book that I have accumulated over the years always seems to only touch on the subject lightly, like a quick review. I am looking to find some good, in depth and intuitive reading about converting between the three and also mastering bitwise operations. I know this is something that is covered in basic courses but for some reason I have never been able to really master it.

hag++ 24 Junior Poster

Welcome to the forums. I recommend reading the forums rules because you will see that people will not help you with these kinds of questions. You need to first learn the basics of what to do (Read books, classes, etc...), post your code, then if you have problems people here can help.

hag++ 24 Junior Poster

The structure of you program overall is a little off. The option to Quit should really only be contained in the main program loop. So you should present all of the options that the program can do (which includes quit) just in the main menu.

hag++ 24 Junior Poster

node &getNode(int index) { //NOT TESTED
if (index <= getLength() || index >= 1){
temp = new node;
temp = head;
for (int i=index-1; i>0; i--){
temp = temp->next;
}
return &temp;
}
}

Hi everyone,
I receive this error msg: "invalid initialization of non-const reference of type 'node&' from a temporary of type 'node**' "

I cannot change the return type of the method so how can i return that reference.
Thanks

I really dont know whats going on here, there are a few things that are weird.

One, you method should be returning Node* not Node&. Also, when you declare a new object of type Node, it should be

Node* temp = new Node;

If you do those things then you don't have to return anything special, just return temp.

hag++ 24 Junior Poster

I have always done something like this

if (!myfile)
{
  // error message
// exit (1)
}
// do file stuff here

I usually do this as well..... however you can use the fail method which is contained in the newer fstream lib

ifstream someFile("whatever.txt");

if (someFile.fail())
{
   // put error message here and exit program
}
hag++ 24 Junior Poster

Ok so first off.... code tags.
And second.... what the heck is this??

if string openfile(" image.bmp")
hag++ 24 Junior Poster

Well that sounds like fun...... Why don't you start by posting code that you have already written so we can take a look at it. Nobody here is going to do the work for you

hag++ 24 Junior Poster

I agree with matt, HKEY_CURRENT_USER is just a const value or enumerated type, so you would need something like a switch case statement to cout the textual representations

hag++ 24 Junior Poster

What about calling the generateString function within your buttonclick function, except have generateString return the string instead of void

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
	String^ getgenerateString = generateString(); 
}

String^ generateString()
{
	String^ sendThisString = "SendThis";
         return sendThisString;
}
hag++ 24 Junior Poster

If you wanted to use your array of struct outside of that method's scope (myFunc1) you need to return to something, then pass it to another method (like myFunc2)

hag++ 24 Junior Poster

Well the problem with that is once a .DLL is compiled you can't edit it directly, you need the C or CPP source file(s) used to create that DLL, then you edit those

hag++ 24 Junior Poster

You just want to dynamically allocate a new array of your struct right? Like this:

myStruct* mySimpleClass::myFunc1 (int arraySize) {
   myStruct struct1 = new myStruct[arraySize];
   return struct1;
}
hag++ 24 Junior Poster

I agree with jwentwing.... we are not a homework service

hag++ 24 Junior Poster

People on here are not going to respond to your post, it is junk. Why? Well first please read the posting rules (that will pretty much tell you why) You can't just say heres my program, what do I do to finish it? You need to put in the effort, and if you get stuck on a certain part, then post your question.

thomas_naveen commented: agree +1
hag++ 24 Junior Poster

I have gotten the Side by Side config problem before. I made a simple program to modify the Windows XP registry Hive files using the Win32 API and it worked fine on my laptop (The comp that I created it on) However on some computers and in a PE enviroment I would get a side by side error. I believe it happens when you dont have the correct C++ runtimes installed, that is just an educated guess though because I actually never figured it out completely

hag++ 24 Junior Poster

Its kind of hard to help because I don't know what your input files look like but I noticed two things. Lines 21 and 80 are

while (source.fail())

Those should be if statements because it will continuously loop if the file open process fails. Also, have you put a couple 'cout' statements for height and width to make sure they are correct? If they are not, your for loops will not act the way you want.

hag++ 24 Junior Poster

No, its a simple standalone EXE

hag++ 24 Junior Poster

Quick question. I have a program that will run perfectly fine in the Debug version (Using MS VS 6) but when I set it to Release and build it, then set the command line arguments (or run it from the comman line) it blows up. Any ideas why this would happen??

hag++ 24 Junior Poster

We help users based on specific question, not "Can you do this for me?"
Start with a UML diagram to model ure class and go from there. If you get stuck at a specific point, post the code

hag++ 24 Junior Poster

Also, daniWeb != homework service

hag++ 24 Junior Poster

Provided I have no code to look at, if your programming in windows you need two "\" in the filename if you are defining the path explicitly. However, the way you are doing it you only need to type one backslash. Have you tried outputting szFileName to see what it contains??

hag++ 24 Junior Poster

Also in line 30 you have

for (int k = 1; k = 0; k++)

the problem is that you are not testing for anything, you are reassigning k to 0 because you are using the single equals

hag++ 24 Junior Poster

Well first, thanks for all the replies. Second, Im glad that everyone here has confirmed what my hours of research have told me. I was starting to think I was either being really dumb are that the prof gave us somthing totally wrong. It should be interesting going to class tonight to see what he says. Again, thanks to all!!

hag++ 24 Junior Poster

That's what I am trying to do but am not exactly sure how to get my file contents into an array.

Well there are a bajillion ways to do that but.... a quick dirty way:

fstream iFile("myFile.txt", ios::in | ios::beg);
const int MAX = 15;
string words[MAX];
int index = 0;

while (cin >> words[index] && index++ < 15);
hag++ 24 Junior Poster

normally we try to help people here an not do the work for them but yea.... ok

hag++ 24 Junior Poster

i Know ure new to posting here so... please read the "Before you Post" guides in the forum list. USE CODE TAGS!

hag++ 24 Junior Poster

Ok, having some serious trouble here. My proffesor told us to write a progrm (what it does really doesnt matter here) however he wants a FULL color menu in the console. He showed us an example of what he wants, it was very cool, it had a red backround, then a giant blue box in the forground with all the menu selections and he even incorparated the little shadown on the bottom right side (looked like a typical dos program menu) He wrote his in assembly language (we dont know that yet) but he said that you can use system(); function with the 'color' command to do the same thing. However, when researching this online, people were saying that it is impossible using color command because you can only change the backround and foreground of the ENTIRE field, not certain areas..... is this true???

hag++ 24 Junior Poster
void initialize()
{
	input.open ("WUexamp1.txt");
}

Files should not be opened this way. You should pass the file name and the fstream object as reference. Like this:

char fileName[] = "input.txt";

bool initialize(char[] fName, fstream& iFile) {
    iFile(fName, ios::input | ios::beg);

    if (iFile.fail())
        return false;  // Indicates file open error
    else return true;
}
hag++ 24 Junior Poster

TBH, I cant read your code.... You used code tags but no indentation..... people are MUCH more likely to help if your formatting is good.... or even readable

hag++ 24 Junior Poster

When you pass an array to a function, you only need to pass the name of the array (i.e starting address) Do not include size declarations

pickColor(color[3][19], red, green, blue); // WRONG!
pickColor(color, red, green, blue); // Correct
hag++ 24 Junior Poster

So, you if else satements:

if (r<=3){
		return 100;
	}else if 
		(r<=6);
		return 80;
	else if 
		(r<=9);
		return 60;
	else if 
		(r<=12);
		return 40;
	else if 
		(r<=15);
		return 20;
	else
		return 0;

if you have more than one statement in any if/ if else statement, you must enclose them in braces. Like this:

if (x > sum_number)
{
    y = x + 5;
    return y;
}
hag++ 24 Junior Poster

I'll give it to you for 1 zillion gazillion quintillion dollars?

Ill do it for half that =) Im cheap heheh

hag++ 24 Junior Poster

Kind of a crazy idea but what if you write all of the ints/ doubles to a txt/ binary file then read them back in as chars?

hag++ 24 Junior Poster

Yea, looking at your code makes my brain hurt.
A) Please read the forum rules on Code tags and....
B) You need to work on your style

hag++ 24 Junior Poster

Your code looks like this:

for (int i = 0; i < sum_number; i++)
{
cout << "I cant read this code!!\n";
}

Code should look like:

for (int i = 0; i < sum_number; i++)
{
       cout << "I can read this code!!\n";
}

Oh and one more hint, MOST compilers have an "auto fix" style feature that automatically aligns the messed up code for you. For example, in Visual Studio, if you select all your code (Ctrl + A) and press Alt + f8 it will auto format. Then you can just copy and paste your code to the forums

hag++ 24 Junior Poster

how i can do database in c++

Ok, well first, I would read the rules on Posting in the forums because this is not a good question. This forum is for helping people out with the areas of C++ that they are having trouble with, your question is too broad. You need to do some searching on google, get some books, etc.... post code and then people will help you.

hag++ 24 Junior Poster

well if u posted the answer and i ddnt understand does that means i'm nt C++ programmer, anyway if u ready 2 explain whatz the right answer then appreciate it.......if not thanx for ur advices and good bye

Sorry to add to this already out of control fire BUT it doesnt really matter what language you have programmed in the past (if any) you always need to declare variables BEFORE you use them.... its not only C++

hag++ 24 Junior Poster

Just an idea.... im not sure if this is what you want but, you could create a struct that contains the chemical name and chemical makeup, then create an array of that struct to store file contents, which is easy. But in order to list in ascending order you HAVE to sort through all of the chemicals, I dont understand why sorting is not allowed....

hag++ 24 Junior Poster

Man you've done most of the work, just call your function in main, here is the code with some changes:

#include <iostream>
#include <iomanip>

const float PI= 3.14;

float circle_area(float &radius);

float circle_area(float &radius)
{
	using namespace std;

	float area= PI*radius*radius;
	cout<< "The area of the circle with radius "<<radius<< " is: "<< area << setprecision(2) << endl;
	return (area);
}

int main()
{
	using namespace std;
	
	float radius;
	cout<< "What is the radius of the circle:> ";
	cin >> radius;
	circle_area(radius);
	return 0;
}

Intel

That will work but a function should really stick to only doin one thing... either calculation or cout, since this is not a complex task.

float circle_area(float radius)
{
	return PI * radius * radius;
}

Then do the cout's in main

hag++ 24 Junior Poster

Ok, first off, please read this before posting code again:
http://www.daniweb.com/forums/misc-explaincode.html

Second, you need to accumulate the numbers that are entered by the user. Depending on what you have learned so far, you can either use an accumulator (the numbers entered by the user are added to this variable with each iteration of the loop) or you could use an array, then add all the elements in the array, get the average, etc...

hag++ 24 Junior Poster

> (I loop it 250 times)
...
> srand(unsigned(time(NULL)));
Unless your code also takes 250 seconds to run, then srand() is always going to be seeded with the SAME value, and rand() is always going to return the SAME value(s) as a result.

srand() needs to be called ONCE only, at the start of main.

Yep, and remember that srand seeds off of the system clock every SECOND. Your program will loop through many times per second and all the random numbers will be seeded with the same number, which is why the dice are not diff values

hag++ 24 Junior Poster

he told me it was wrong because the second for loop being n is searching a object that has no elements inside, the returning parts not rly my issue all i need to understand is how to pass each array from find2D function to arrayFind() to do the searching

See my post right above yours :) and two, it depends on what your instructor wants. You either use two for loops in the same function to search the array ( I put an example on the top of the forum, the one using the pointers) OR follow the pseudocode on my last post before this

hag++ 24 Junior Poster

yes but the question says i have to call findArray within the new function find2D

ex: pseudocode

function find2D, finds an element x in an n × n array A. The
function find2D iterates over the rows of A, and it calls the function
findArray shown above, on each one, until x is found or it has searched all rows of A

Ok so you need two functions that both accept the 2 dimensional array. One function will update the "row" count and call the second function, which searches ONLY the specified row, but ALL columns in that row. The second function either returns the desired value or returns some kind of value indicating "value not found"

hag++ 24 Junior Poster

Does Anyone know how i can convert this 1D array (findArray) that checks for an element Into a function called 2Dfind that searches a 2D and pass each array to arrayfind(), to do the searching

int findArray(int A[], int n, int x)
{
   for(int i = 0; i < n; i++)
     if(A[i] == x)
       return i;
     else
       return -1;
}

ive been told i dont need to use another for loop but im still unsure how to make this new 2Dfind Function

i tried this but i was told its wrong

int 2Dfind(int A[][], int &n, int &x)
{
	for(int i = 0; i < n; i++)
	{
 		for(int j=0; j < n[i]; j++)
  		{
			if(A[i][j] == x)
				return i,j;
					else
					    return -1;
		}
	}
}

It is wrong. The reason being is return i,j; You cannot return 2 values this way. In order to return 2 values you need to "package" them in a way that you are returning multiple peices of info in only one value, which is why it would be easier using pointers. You could also use structures or reference variables

hag++ 24 Junior Poster

You do need a second for loop (one for the rows, one for the columns, in the array) It may be easier to use pointers:

int* return_ptr(int str[][20], int x, int max_rows, int max_col) {
	int* a_ptr = new int;

	for (int i = 0; i < max_rows; i++)
	{
		for (int j = 0; j < max_col; j++)
		{
			if (str[i][j] == x)		
			         return a_ptr = &str[i][j];
		}
	}
                return NULL;
}
hag++ 24 Junior Poster

Also rkulp, please search the forums for already made topics that include your problem before posting a new instance of it. Click here:
http://www.daniweb.com/forums/thread253567.html

hag++ 24 Junior Poster

We first of all, I said im writing MY first c++ program, that does not mean that haven't been playing around with other code for a while.

Secondly info about the mud can be found at lithmeria.com (still beta) and your sarcasm is unappreciated.

Thirdly im not throwing around terms here..

I already have one loop that handles data back and forth between the mud client and my server. i figured that i would have to have another loop that handles data back and forth from my server (which will also contain a client) and the MuD server. not sure exactly how important thread synchronization would be (would i need to use semaphore). I dont want to loose any data in either direction.

So im thinking i need 2 loops going at the same time with some way to talk back and forth between them (hence my semaphore question)


Thanks for the sarcastic introduction to the community Salem. Im sure you feel like a big man squashing people after their first post. Jerk

Well, first off I guess I should say Welcome to the forums!.... ok the second thing is, I know sarcasm wasn't really called for here but it would be easier if you posted your code with a lot of comments on where you need help/ are confused about.

hag++ 24 Junior Poster

combining tutorials never works for a newbie to C++

Newbie to C++ trying to use WinAPI is going to result in a lot of headaches and errors. I agree with sticking to a console app.

hag++ 24 Junior Poster

Unless there is some form of compensation involved, ahem.

Oh... well then... now where talkin :)

hag++ 24 Junior Poster

i am going to make the Database (i.e enter name, phone # etc) but how i will make it permanent (i.e to save it permanent). When i close the program and reopen, my previous Data that i had enter should Present???

How i will make it???

Write to a file.

I would have to agree with WaltP lol.... Unless your running a computer with non-volatile memory in it :)