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

What values are in the compe array?

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

So what have you figured out?

Didn't you read the Rules and Read Me: Read This Before Posting yet?

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

Look up the bubble sort. It's much easier than the selection sort.

Comments such as "you have no idea what you are doing", "you shouldnt code this or that its horrible" are NOT welcome.

Im learning - you all learnt at some point too. So let me work at it. I'll get there. Just have some patience!

Touchy, aren't we? Has this happened a lot to you in 14 posts?

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

If you get errors, the technique to get help is to post the errors exactly as you see them (cut & paste, don't retype).

Based on he code snippet you posted, you are only missing the randomizer srand() .

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

im confused as to how to write an error checking function and how to write a decode function which decodes morse code. It cannot simply be a backwards of the encode function because ONE morse code is made up of FOUR characters...? (if you get what i mean?) i am not allowed to use a 2-d array... is there any other way to do this?

Why can't it? You know the length of your input value (.- is 2, -.-- is 4). So look for a match that matches both characters and length. (.-- and .-.- would be rejected for .- because neither are two characters.

Error checking? :: my thought on this is that i should pass the entered string to a new function which loops through the string, filtering out errors... however. i do not know how to start coding this function.

This depends on how you define error. Since we don't know your definition, can't help.

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

Good grief, nobody would ever use the same computer for ten years! One exception, maybe the government does for flight control.

Nobody? You don't know the people I know...

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

I would also suggest better formatting. See this and pay particular attention to the Indentation section. As it is your code is very difficult to follow.

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

Your formatting is still hiding your errors. Pay closer attention to the section on Indentation and you will see a glaring error when you indent properly.

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

If you learn now to format your code you will discover it's easier to find errors and your code will be easier to read. This is very worthwhile when you get to more complex programs. It also helps us understand your code.

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

In your first post you did good -- mentioned what you wanted and what the program actually did. This time you left it up to us to figure out what happens. always tell us
1) what you did,
2) what the program did, and
3) what you expected instead

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

When writing my pseudocode I declare my variables in a module called housekeeping(). We are currently working on reading input from a file or files rather than asking the user directly for input. I am a bit confused how this might work with my pseudocode though. I know how I might write it out but am unsure of the file I am pointing to. In this project I would need to point to the file which contains the player’s number, name, etc.. The print chart is an output file so it would not come from there. Where and how might I include the fictitious input needed for the program to run?

Open input file [I]X[/I].  Read from [I]X[/I]
Open output file [I]Y[/I].  Write to [I]Y[/I]

Basically, that's all you need for terminology.

char columnHead = “PLAYER NUMBER FIRST NAME LAST NAME BATTING AVERAGE”

In the line above would you space twice after player number and 16 spaces after first name because that is how many char spaces are allotted? Or is it just spacing enough between the headings to allow everything to fit and look nicely?

Leave enough space for your field size plus a couple characters between columns.

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

Turbo C Ver 1 also prints, so it's probably a bug at least through ver 3. Borland 5.5 works as expected.

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

Please, you need more consistent formatting. See this for ideas, especially the use of indentation (TABs vs. SPACES for one)

Also, don't use system("pause") when there are better solutions...

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

okay so the second part of this assingment is: Using a sort routine of your choice, sort the numbers in each of the rows of the array and display the sorted numbers again on 5 lines of 10 numbers each


i have no idea how to do this...in a 2d array. please help!

You can't do this part until you get the first part done. Did you? If so, we can't see the code...

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

sorry, I should have said I changed it to this,

char *getString(char *string) {
	scanf("%199s",string);
	return string;
}

to provide for the null char. Thanks again:)

We still recommend:

char *getString(char *string) {
	[B]fgets(string, 200,stdio);[/B]
	return string;
}

It's just too easy to make a mistake with scanf() . And why do you need to pull in the and execute the parsing for %d, %u, %i, %g, etc when fgets() requires nothing extra but reading a string. Safely.

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

hhhhmmmm....could someone give me a jumpstart? thx

Since I did, you're welcome.

If you are having problems, you need to give us some info. After 559 posts, you should have some idea how to formulate a question that tells us what issues you have trouble with.

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

Wouldn't it be better if your parser at least removed the color tags from syntax-highlighted code? Some people aren't aware that color tags don't work in syntax-highlighted code tags (or they paste it from their editor, which for some reason has the code all colored), and then all we see is a bunch of BBCode crap.

Nyah. If they want to screw up their code and post without a PREVIEW, let them. We just don't have to read it since they didn't care enough to verify their post.:icon_twisted:

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

Just on the screen

And your formatting is still not very good.

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

Okay, here's what I have so far:

#include <iostream>
#include <conio.h>

void main ()
{
clrscr();
int array [3], t;
for (int  x=0; x<3; x++)
{
	cout << "Enter integer number" << x+1 << " : " << endl;
	cin<< array[x];
}
for (x=0; x<3; x++)
{
for (int y=0; y<2; y++)
{
	if(array[y]>array[y+1])
	{
		t=array[y];
		array[y]=array[y+1];
		array[y+1]=t;
	}
}
}
cout << "The integers in ascending order are : ";
for (x=0;x<3;x++)
cout << endl << array[x];
getch();
}

There are six errors so I have a lot of work to do :icon_frown: but is that a start? Or am I completely off?

Looks pretty good so far. Here is some work you never knew you had to do:
1) #include <conio.h> -- old, non-portable header. When you get a job you probably can't use it, so stop now.
2) void main () -- main is NEVER a void. It's an int, always has been. See this.
3) clrscr() -- same as #1
4) getch(); -- same as #1
5) Formatting your code. It's not as bad as a lot around here, but check this out for more ideas.

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

In this code of yours (formatted for readability):

if (strcmp(num, search) == 0)
    {
        ...
    }
    [B]// is the following IF necessary?  Doesn't the ELSE automatically
    // assume this condition because of the above IF?[/B]
     else if (!strcmp(num, search) == 0)
    {
        ...
    }

You can leave off the second IF because it's true by default.

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

how to print /n

Start your own thread. Don't hijack someone else's discussion.

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

First things first: Format your code

2. Remove all the duplicate letters in the key phrase.

Nested loops.... Replace any duplicates with SPACEs. When done, compress the SPACEs out.

3. Remove the letters that remain in the edited key phrase from the string of the 26 alphabet letters.

This one is easier than above, since you know there are no duplicates. I assume you know the relationship between letters and the value of the letter (A==65).

4. Connect the edited key phrase to the front of the edited alphabet.

This you can probably figure out.

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

I would guess that the 2 following lines do not equal search, since that is the only delete requirement. You need to either
1) know what the next two lines contain so you can compare them
2) just read off the next two lines when you get to a line to delete

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

See this info. feof() is the same as .eof()

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

One possibility to consider is to allow BOLD and ITALIC using language-specific tags. Just a thought.

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

FORMATTING please.... SPACES and NEWLINES are your friend so the code can be read:

if ((time_and_date[i].start.hours <= 7 )  &&
        (time_and_date[i].end.hours   >  7)  &&
        (time_and_date[i].end.hours   <=16))
    {
        temp_rate = ((count_rate*60) + (time_and_date[i].end.minutes)) * 0.12;
        rate = (((time_and_date[i].start.minutes)) + (hour_rate*60)) * 0.15;
        rate_two = (rate + temp_rate);
    }
    if ((time_and_date[i].start.hours >  16)  &&
        (time_and_date[i].start.hours <= 23)  &&
        (time_and_date[i].end.hours   <= 23))
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Peoples i have tried to make this simple progrem in C...
that will print alphabets A to Z and their equivalent ASCII code.. like this
A 65
B 66
.
.
.
Z
here is da source code...

Please use English. It's "here is the source code. Unless your name is Stepin Fetchit,. Thanks. And use CODE tags...

int main (void)
{
	char code;
	for(code = "A";code <= "Z"; code += 1)
	printf("%c, %d", code[B],[/B] code);
	getch();         //  ^
}
Belrog commented: If you can't use basic grammar, you can't code. +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

can u help me what I am doing wrong in above program??

Yes, read the link you were given twice. It tells you how to do what you want. If not, ask a specific question.

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

Is there something about CODE tags you don't understand? If not, you can either ask or read those words on the back of the input box for information.

The project states "Test it with a main program that takes as input an integer count followed by that many values." Where did you read an integer count? Doesn't getline() read a string, not a list of integers? You need to use a loop to read (and output) your numbers.

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

Where's your C++ case reserved word?

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

No, you haven't tried everything. You haven't tried one suggestion nor answered one question I posted. Can't help you if you don't care enough to explain your thinking or think about suggestions given.

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

Ok, is this what you were thinking?

No. Get rid of the char* and just use string . It'll make the code simpler. The problems I see so far:

char *entireString = new char[0];    // this defines a char string with no characters

entireString[line.length()+1];    // what are you expecting these statements to do?
keys[line.length()+1];
values[line.length()+1];

strcpy(entireString,line.c_str());  // don't need this at all, plus you just screwed up your memory
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

ohk going back to my code with count...
in that too while(fin) is running endlessly...can you tell me the reason why?...
thanx in advance...

I just did.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while(fin)
  {
    ch=fin.get();
    fout.put(ch);
    
    while(ch==' ')
       ch=fin.get(); //*****

  }

If the last character in the file is a space, your inner loop will run forever because ch is never changed but the fin.get() has returned an error which you never test for.

Go back to your other code with count . It should work. This code will skip each character that follows a space. And make sure you always test for an error from all of your your inputs.

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

If count is 0, the space is written. count is then incremented. If another space is immediately read, it is not written because count is no longer 0. He has effectively removed extra spaces as his original post describes:

i have made a program on text file to remove extra blank spaces in a file but it is not working correctly.

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

You don't need c_strings. Just look for the two characters that begin and end a value you want moved and use the substr() method to move the value.

And why are you indenting 3 miles? Too much indenting is almost as bad as no indenting. 4 spaces is enough for any indent.

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

Also, every line that has the word count on it needs to be deleted. It is preventing those spaces from disappearing.

count is used to delete extra spaces. Removing them will prevent spaces from being deleted.

[EDIT]
WaltP you missed the fil ifstream at the bottom... so he actually should see more output on the screen...

No, I missed the cout at the end. But miss something I did...

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

Nothing else is output to the screen. What do you expect to happen? If you think there's a problem, add a few cout statements to follow what's happening and pinpoint the problem.

And isn't this a C++ program? Why are you using the extremely dangerous C function gets() when there are perfectly good C++ input functions available?

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

You can't possibly get 155.419 from an unsigned long, there is no decimal point from integers. You need float or double.

And dividing two integers always gives an integer, even if you load it into a floating point number. For example:

double dval;
dval = 25/2;

12.000 is loaded into dval, not 12.5.

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

I can't see how this code does anything. You have 3 nested while loops all exiting on the same condition. And if you read this you'll see your condition is wrong ( feof() is the same as .eof() )

Then in the second loop, you read a single character and output it. Other than that, no other output of note.

If you happen to find the input string in the file, why do you reread the file?

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

it should be if the user hits either the Q or q then exit the loop., but when I was using the or, it would not exit the loop.

Yes, but this statement is "if == " not "if !=" which is what you were using in the code.

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

Rule of thumb -- if you need both, use && (and). If you need either, use || (or).

Test it by using English (or your native language): is it "if != Q or q" or is it "if != Q and q" and you get the operator to use.

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

what do i do when the years are not the same? i need to be able to change the years

That has already been answered.

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

Simple loop with a test inside.

would it be a for loop with an if statement?

Duh.... :icon_wink:

for every year between one and the other, use my leap year function to test if each year is a leap year and for every year that its true, add one day?

Yes.

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

Close, but not close enough. You'd get the same answer if the years were 2001-2005 and 2004-2008 but in fact the former has one day les because there's only one leap year. You need to look at each year individually and deal with LY. Simple loop with a test inside.

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

Good day.

G'day, mate!

I have a few questions. I wanted tge program, each time a customer chooses an item, for it to be displayed as he/she chooses. It's also telling me that index is undeclared.

Please be a little clearer. Your first question has an obvious answer, therefore I must be interpreting it wrong. The second doesn't make sense unless it's a compile error. And you know enough to post the what and where the error is if that's what the problem is. So that can't be it, either.

And haven't we mentioned formatting your code at least once? Or was that someone else?

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

Unresolved external means the variable being used does not exist. It was never defined at the spot you are attempting to use it.

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

Yeah. As far as I am concerned, the computer is there to serve me, not the other way around. ;)

Then why are you using WinBlows? :icon_twisted:

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

So what was the problem? How did you solve it? Your answer may help someone else later.

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

OK, I looked more closely at your code. I made an assumption before.

#1) I see you're still using the getch() , clrscr() , and the evil gets() . Bad. Very bad. You're writing C++. Stop using C.

#2) In the loop, the code

if(stricmp(xyz.getname(), name)!=0)
{
...
}
if (stricmp(xyz.getname(), name)==0)
{
...
}

is the same as

if(stricmp(xyz.getname(), name)!=0)
{
...
}
else
{
...
}

Use the else version -- it's easier to read.

You're saying the code you posted isn't working? Then add some output statements to watch the program's flow and see where it seems to be going wrong.