WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) It isn't, really. Reference param passes the address into the function rather than the value.

2) Yes

3) new doesn't store anything. It defines space and puts the address of that space in the variable specified.
Consider variables as boxes you store stuff in. Each box can hold a specific type (books, school papers, clothes) and amount of data. Well, new is like yelling to Mom "Hey, I need another box!" She gives you one after making you say Please and you can store your action figures in it. It just gives you more storage space you didn't have when you started.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm sorry I thought you would use my code to see the error for yourself first hand.

Why?
it's so much faster for you to tell us than for us to create a project, add your code, and compile. And I for one have many other posts to look at.

Error is that Convert(int) already has a body.
I think it's because I'm trying to give it 2 commands (for finding hours and finding remainder).

Yes. What does Convert() do? Why not give the functions names that makes sense? Neither Convert() function really converts.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Error #1- You didn't use CODE Tags
Error #2- You didn't bother to tell us what the error you're talking about is. This isn't the Psychic Homework Help Desk.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The Amish -- no phones, no modern conveniences.... You know, the buggy drivers.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Problem #1: switch(inst[50]) -- this command only checks the value at inst[50], which is the byte one past the end of the array inst. What are you trying to test here?

Problem #2: case 1: -- You entered characters, not integers, and this case is an integer value.

Is there anyway that in the first switch statement i could use both Char values and int values?

No. Since you don't have any integers, it doesn't matter.

if i wanted the user to enter either 1 or a 2 and they enter a z or an f or something, i would like it to prompt them again... but i can't figure it out...

You've already got it set up properly in the default case.

Your understanding of integer vs character needs to be fixed. If you are reading a character string ising cin.getline(inst, 50); , and you press the keys 2 5 1 enter, you did not enter the integer 251, you entered the characters '2', '5', and '1'.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Or add another value called HighCard. For a pair, set HighCard to the value of the pair (4 for Fours, 11 for Jacks).

This would be helpful for Pairs, Trips, Straights, etc.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I have compiled the code again, and it does give me the output above!

So did I and I got

C:\>x
Enter two numbers:
10 20
You entered: 10 and 20!
10

C:\>

Try looking at the code you're compiling and compare it to the posted code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You really want us to look through 650 lines of code to
1) find you compare function?
2) figure out what's wrong?

Sorry, nope. Pinpoint the problem areas and we can see what we can find.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The code you posted cannot display the output posted.

The simple solution is use a FOR loop.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Very simple. Why don't you try something and if it doesn't work, post it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Write calMonth()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

because function is not being called...

Prove it. Add printf() statements to prove it's not being called.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Or if stringstream is too advanced, atoi(argv[i]) will also suffice.
i will be an index into the argv array.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

A couple things on your statement

while(fscanf(in,"%s %s %s\n,",&day,&mon,&year)>0)

1) you don't need the &. Each variable is already a pointer since they are arrays.
2) >0 is OK if only one of the values is needed. Use =3 if you want all values to be correctly entered.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What are the values of wordStart, wordEnd and command[wordEnd] during the loop? cout is your best debugging tool.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So post what you have now.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, easiest is to open the file for read and check for an error.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And....?

Explanations help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I meant:
while (in_stream.good() && in_stream.get(A) != ' ')
not the other way around. This is why I never got good grades in school :)

Well, since we frown upon giving solutions to people, maybe you should refrain from posting code anyway. After all you don't get the grades. They do...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Please format your code so we can read it properly.
2) Do not use gets() , here's why.
3) main() is not a void function. See this.
4) To get help, you need to show an attempt. There is no attempt in this code for 4 & 5.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use peek to see what's ahead one character. This is probably the easiest way, but maybe not the most efficient.

Yes, inefficient, and bad. You have to read the next character anyway, so why peek, then read?

Look at line 27. Is that an assignment?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, in your editor's options set the TAB key to add 4 SPACEs instead. All those TABs make the code harder to read.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you are using a C++ string, use the string functions .find(), .substr(), .erase()

With a simple GOOGLE search I found this

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes, it's completely possible. Set up an index array idx . Then month[idx[2]] and dblval[idx[2]] will be a matched pair.

During the sort, check arrayEntry[idx[i]] with arrayEntry[idx[i+1]] and if they need to be switched, switch only idx[i] and idx[i+1] . The actual arrays stay in their original order, only the index array gets sorted.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks, that push was actually VERY helpful.

Good.

I'm almost done, but there's an algorith to compare the colors and i'm not sure how should i do it, nothing good comes in my mind and i actually wasted pretty much time with it

Since I don't know the algorithm, nothing comes to my mind either.

btw, how do i check the fopen function for errors?

Try This
And while you're at it, This Too

i have also put in the \n in the scanf to take it out

:icon_question:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
int main()
{
	int i, j, k=0, test, n, m;
	char **garden;
	char c, colors[100];
	FILE *be;
	be=fopen("G.IN", "r");    // How do you know the file was opened correctly? 
                                  // You didn't check for any errors.

	fscanf(be, "%i", &test);  // You read the first integer but the \n is
                                  // still left in the file. I suggest you read
                                  // a full line and convert the value to integer

	for(i=0; i<test; ++i){
		if(fgetc(be)>64 && fgetc(be)<91) 
                                  // This statement reads the next two characters and
                                  // checks the first to be > 64 and the second < 91
                                  // You probably want this to be after you read the 
                                  // line then check the first character in 'colors'

		fscanf(be, "%s %i %i", colors, &n, &m); 
                                  // Again, read the entire line then convert.
	}

	//system("pause");
	return 0;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. An array is a list of values. Values can't call functions. Only code can call functions.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you didn't post any code, we have no way of knowing what you did wrong. This is a very simple task and how you tried to do it will tell us what to suggest. Otherwise you get suggestions like the one above by rxlim

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) In English, there is always a SPACE after punctuation!!!!!!
2) Dividing ints give you ints. 3/4=0 not 0.75. 8/6=1 not 1.5

During the division make sure one of the values is cast to float (float) 8 / 6 Also, nmb? Please reread the Member Rules -- Keep it Clear, first and last points.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This is my computer science project,we were told to make any software we wish to make,so I thought about making a calculator,below is the code,but it doesn't seem to be functioning well,could anyone help and tell me what went wrong(I am using borland cpp 4.5 compiler,this program uses getch() to read the keystrokes)

1) In English, there is always a SPACE after punctuation
2) As for it not functioning well, try unplugging the computer from the wall socket, then the lights won't go out when you run the program

Now I admit I'm guessing on #2 what "doesn't work well" means since you didn't bother to tell us. If I'm wrong, try explaining the problem.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What fixed it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Line 26:
Ouput account, string2, and string3. See what the values are.

Also, are string2 and string3 useful names? What are they for? The answer will give you better variable names for them.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ctrl, Alt, Shift are not 'keys', they are modifiers to keys. C is a key, value is 67. Ctrl-C is also a key, value 3.

Look on Google for information about Sendkeys

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You never put a value into d therefore if ( d < 1 ) is comparing junk with 1.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My point on the comments refers to commenting something like this

char character = getchar(); //get a character from stdin

getchar() is a function from the standard library. Its well documented, so I consider commenting its functionality redundant. That said, if your Prof wants comments then give him/her comments.

That may have been your point, but you included

/* Function prototypes */
void process(char input);
void update(char words[][51], int position);
char * toString(char character);

/* the global variables */
char words[100][51];	//the array of the words inside the text
int lastWordPos = 0;	//position of the last word in array words

char tempWord[51] = "";	//temporary array for storing a word
char tempDigit[51] = "";//temporary array for storing a number
	
while(character != '0')	//as long as the character from stdin is not 0, keep looping
strcpy(words[lastWordPos], tempWord);	//add the word to the word list
strcpy(tempWord, "");			//reset tempWord, so that it can be used again at the next loops, if needed
lastWordPos++;				//increment the position of the word list

in your remark. If you didn't mean these, you should have been more explicit. As a veteran programmer, I understood your remark as "don't use comments". How will noobs interpret it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you go to the casino, you will never see the dealer 'pick a random card from the deck' (your technique), they 'randomize the deck' (shuffle) and deal top to bottom (use an index).

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Write some code. Then we help fix.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try running the program from the command line and add your parameters there. See what happens.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, why all the comments its really distracting.

Because good programmers comment their code so others can follow it.

sorry its an assignment from my university so I have to write all that comments. I hate it too so please bear with me :/

Don't apologize. Keep it up. Comments are critical if you want to make programming a profession.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

ASCII characters are just numbers. So if you wanted onthe the upper case letters for example, the are 'A' thru 'Z', or 65 thru 90. So
1) limit your random value from 0 to 25 (number of letters)
2) add 'A' or 65 to it.
That will give you all the upper case letters.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Where you got the idea ^ means raised to the power in C is a great question.

Belaying that, look in the math.h header for the function pow()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

now what do you think is wrong with my new code???

As always, you aren't using CODE Tags.

Also, give a detailed description of what is happening wrong. Each time you post, explain! With CODE TAGS!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

To change something you need an equal sign.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

5/9 = 0 so you are multiplying by 0.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

and obviously the head of the Department of Redundancy Department, too...

As for the question, what kind of error would you like it to have? You have to program the one case statement :icon_rolleyes: with an error the compiler can't handle to get a compiler error.

Please proofread your posts before you submit them to be sure you have made accurate and understandable statements. If not, feel free to edit your post before submitting, or click the EDIT POST button after submitting to clean up any questionable information.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

never heard of a forward key

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Two things I see: for(jj=0; jj< (n-(1-j)); jj++) /* inner loop and compares adjenct items */ I don't believe jj< (n-(1-j)); is doing what you want. Try calculating values of jj using various values of j.


Are you assigning or comparing cnt in this IF statement?

if (cnt = MAXIMUM)
                printf("full-overflow\n");

Also, please use better formatting. Your indentation is very inconsistent making the program a little hard to follow.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I did this....simple but works

int main()
{
  char c1, c2;
  c1 = getchar(); // get first input
  c2 = getchar(); // get second input
  if (c1 == '\n' && c2 == '\n') // if post inputs are enter
     exit(1); // exit
}

So what happens if someone types in " [ENTER][ENTER]"?

Put each getchar() in a loop testing for '\n': while (getchar() != '\n');

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry Walt, I guess I don't really understand what you are asking.

Really... Then we need to teach a basic English concept.
Q1: What constitutes the beginning of a sentence? Rephrase: What is the definition of a sentence? How do you know when a sentence ends? How can you tell what the first character of a sentence is?
If you don't understand these questions, you can't really program the task.

the text file from the book to use for testing is this:

this is a TEST file.
the sentences in this file are of varying
lengths. some span lines.

others DO NOT.

How many sentences are there? What is the first letter of each sentence? How can you tell?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I tried using the seekp member function but could not figure out where it needed to go. It just made my output file all over the place.

This is what I tried to get the first letter in the sentence:

inFile.seekp(0L, ios::beg)

I'm just not sure where to put it. I had a lot of problems with loops in my past programing class.

Why? You don't need seekp() at all.

Try answering my questions. I asked them for a reason.