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

:icon_rolleyes:
Now you're getting really heavy into "I'm not going the think anymore, I'll just let them tell me what to do."

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

[edit]
WOW, I guess I took a little too long to post... WaltP already covered most of it. Your tolower() is still not correct though.

To quote Fran, the Progressive weirdo -- "Happens to me all the time!" :)

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
if (game_board[row_coord][col_coord] == '~')

If this is true, count is never incremented.

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

Then you did it wrong. But my psychic powers aren't working today so I can't tell why.

churni commented: thanks for the help - you really are a genius in my eyes! +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's too busy. Too much output peppered throughout the code.
75 lines of code -- 40 cout statements, 6 cin statements. But it's all jumbled together. Can't see the program for the output.

Make some functions to input values, do calculations, output values. It will make the main function small and concise, and each function will be easier to read and the program flows better. And moves the output statements into modules which gets them out of the way.

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

i need a function to line up the info with these columns.:

Name Test 1 Test 2 Test 3 Average

here is the code that i have so far.:

####

thanks to anyone who helps me with this.

I don't see any attempt. There is nothing to help with yet.

And stop screwing up your CODE tags. They aren't that hard to use.

eternaloptimist commented: he acts like a stupid jerk. +0
Fbody commented: He's a mod enforcing the rules... +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

By thinking about what you need to accomplish and using a loop to do it. Programming means using your head, not just asking for turn-key solutions to a suggestion. Figure it out. Code it. Then post when you get stuck.

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

the i+1 is just so that the counting of the array prints out to start at 1. i don't think that has anything to do with the numbers in the array... or am i wrong?

and i have no idea if the comparisons are correct or not. thats something that one of my friends had helped me with. it seems to sort the numbers correctly. its just the issue of it adding a gap when it prints out the sorted list in bubble sort

Maybe this will help you understand the Bubble Sort better.

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

Of course it's necessary. And useful. Look up it's uses.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
cout <<"Continue? Enter y or n"<<endl;
cin >> c;      // put answer in variable c

tolower('c');  // convert the character c (not the variable) to 
               // lower case and throw away the conversion 
               // -- didn't put it in a variable
if (c == y)    // compare the variable c with the variable y -- 
               // what is in y?
     main();   // NEVER EVER call main()  It is not a recursive
               //  function. Use a loop

And why are you spacing between most lines? It does not make the code more readable.

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

well, it turned a colon & asterisk into a love emoticon. sometimes u learn things by accident. WaltP: could u please explain step-by-step how to do that?

Look in the start menu under accessories.

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

Enter 2 to quit. Works fine.

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

Then look at your for loops. Are the middle comparisons correct?

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

What compiler?

Why not just do your own ceil() function? hour_labor = (int)(square_footage*(8.0/500.0)) + 1;

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

You don't need to make your questions into comments. They are not code.

As for making the file, try Notepad.exe

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

I hope Quantas is still around. I need to make a phone call...

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

Mistake #1: system("pause"); Here's why
Mistake #2: No formatting. See this. If we can't follow your code, it's hard to help.
Mistake #3: Not posting the exact error message.

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

this is written on the book
1990 by The Waite Group, Inc.

20 years old? Never learn from a computer book older than yourself! Jeez! :icon_rolleyes:

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

This is the code:

//----------------------------------------------------------------------
//
// This lab exercise is to practice rand(), srand() and 
// output formating with help of <iomanip>. It also practices 
// file input and output.
//
// Add a text data file to your project called "lab_4_data.txt".  Put the following
// numbers in it: "23   456    3000    578   9876".
//
// You do not need to create an output file, because the file open call
// will do this for you. 
//
// Compile and run your program. When everything is fine,
// print your .cpp file and turn it to me or the TA.
// **********************************************************************

void showMenu()
{
	cout<<"************************************************\n"
		<<"Enter 1 to build a square root, log10 table     \n"
		<<"Enter 2 to play rolling two dices               \n"
		<<"Enter 3 to print a calendar for 2008            \n"
		<<"What is your choice  ==>	"; 

	return; 
}

Looks like Sir Dragon was right...

Although I saw something about July embedded somewhere in the middle of the program as I was gutting it. Maybe you should just post the relevant code?

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

Depends on how large it is. It works just fine for small arrays -- say 1000 or less. Larger than 10,000 you might want to try something else if the sort takes too long.

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

I don't see any struggle at all. You have posted no code whatsoever.

An equation is an equation. If you've done any C++ you've done an equation, haven't you? + - * / ?

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

and here is my program now,

void main(void)
{
long a,b=1;
clrscr ();
printf ("Enter number to calculate its factorial:");
scanf ("%ld",&a);
if (a==0 || a==1)
printf ("You entered 0 or 1");
else
for (a=a;a>0;a--)
{
b*=a;
}
printf ("Answer is %ld",b);
getch ();
}

but there is still some problem, when i am writing 0 or 1 in the output , it is showing both the statements You entered 0 or 1 and Answer is 1 ..why is this happening so ? i want it to show only first statement when i enter 0 or 1

No more help until you get rid if void main() , clrscr() , and you format your code. No longer wasting my time.

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

Thanks alot Jephthah & WaltP i've learned alot today !!
though

We're learning Turbo C from the book,


can you suggest me a better b0ok to learn modern C language instead of these all functions ?

When was that published? Looking for anything published in the last 5-8 years would be better.

i am in my second year doing part time teaching..thanks for asking

Then you need to relearn C/C++ and stop using ancient compilers that are not standard. Teach your students on current compilers (there are many free ones) and each them Standard C/C++, not all the old Borland/Turbo crap that's worthless in today's industry.

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

... what my teacher teach is only the basic.

No, what your teacher teaches is completely non-standard C that cannot be used in today's industry. TurboC++ is over 17 years old and is so outdated at least 3/4ths of your code cannot possibly be compiled on any current compiler. TurboC 3 I assume? Makes it almost 20 years old.

I hope you aren't paying a lot for your C++ class. You are getting ripped off.

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

dont i need the for loop. The while loop is reading the file the innor for loop in filling the array

No, the while loop is for filling the array. The for loop is useless. Remove the for statement. It serves no purpose. Don't be a smeghead about it.

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

What jephthah says is correct, but by not passing "cowandchicken" into atoi() you won't have a problem.


You need to look at the characters anyway. This is the verification phase of any conversion. Make sure you pass digits at the front of the string and you're fine. Anyone that would blindly pass a non-verified string into a conversion function gets what he deserves.

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

EDIT: Sorry I hadn't noticed this was an ancient thread when I post this reply.

When answering threads you need to read them first. Especially the last post made. There is no point answering if what you're going to say has already been said. And by reading the thread you might have read my post.

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

No, peep, we don't. That's why it's encoded. So you can't decode it. :icon_rolleyes:

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

Good start, although don't indent so far. 4 spaces is more than enough. 32 makes your code unreadable. See this.

for (int i=0; i<3; i++) {
		for (int j=0; j<27; j++) {

If your matrix is defined as 28x4, why are you reading 3x27? Use the dimensions you gave the matrix.

Now add the read command. You're good to go.

Why define a 'matrix' as 1x28? Isn't that an array[28]? You don't need a 2D array.

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

Isn't this basic math? If you know the terms (slope, axis, etc) you already know (or can find) the correct equations. Turn them into code.

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

Do you mean doing the IF statement that declares the number being even or odd, I mean this one:

if (x%2==0)

But then what to do? I understand that we need to make a count but I don't know how.

You don't know how to do d = d + 1; or d++ ?

Also, to make your code readable, please learn to be consistent when you format your code. Inconsistency makes the code difficult to follow and understand.

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

In addition to what Banfa said, you need to learn formatting. Your code is completely unreadable. You should not ask someone else to try and help you with code that cannot be followed.

As for lifelines, you need to keep track of all three individually. Use an array.

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

One problem I see is that you're using the word "random" as a variable. Change that name, because "random" is a reserved word in C.

It is? What's it used for? Please verify before replying.

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

Read the FAQ in the site you linked. All the information is there.

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

3 loops all using number. You should know by now we need details, not vague descriptions.

And if you are passing values back from functions, pass them back. Don't use void functions. That's why they designed int functions.

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

Wow, some people have never worked in the service industries. And never talked to any friends working there.

Any one expecting any specific amount in tipping money independent of service rendered deserves none at all.
I will therefore never give a tip unless the service is not only satisfactory but examplary, and then tip depending on circumstances.
20% is ridiculous, but so is (often) 15%. 5-10% comes first, and if there's a category "tip" included on the bill with a filled in amount when I get it, not only is that crossed out and the amount I pay reduced accordingly, they'll get nothing whatsoever.

Your understanding of the industry is abysmal. People in service industries provide a service over and above the business they work in. And in the case of wait staff, their salaries are below minimum wage because they do receive tips. They are working for you as well as the restaurant. The bill is not for service, it's for the food.
So by deciding 5-10% is normal you are screwing staff. That level is generally reserved for sub-par service.

There are a heck of a lot of whiny waiters claiming they think people who "tip below 18% are cheap".

I suspect you'll find those are the one that give mediocre service, too.

The way I see it, an average waiter waits 3-5 tables an hour. With a completely made up (but low bill) of $50 per table this works out to …

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

Open the file in WORD and output the file as TEXT.

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

Tell you what. Format your code so we can follow it using this information paying close attention to the indentation information, then give us an idea what you are trying to do with the code and an idea how it's supposed to work. And explain in detail what's wrong and where you think it's wrong. Then we might be able to come up with some ideas. As it is, I don't really have a clue what's going on here because the code is a mystery, and it's really hard to read.

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

I suggest, since you asked, you start actually explaining what is going wrong. And pointing to the section of code rather than making us search through 454 lines that we didn't write. Your description

but the random ship placement seems to only work about half of the time and it is just flat out confusing me. Whenever I try to use my debugger it gets stuck at a different spot, whether it is placing user ships or computer ships.

tells us nothing useful. That's like telling the doctor "Doc, I have a pain, it's somewhere" and expecting him to fix it. Think of us a your doctor. If you want to spend 3-10 hours (or more) waiting for an answer because we have to ask more questions, OK. But aren't you wasting a lot of time doing nothing this way? Details.... Give is details.

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

To resurrect a 4 year old post with completely wrong information is pretty bad.

double x=1.5
printf("%ld",floor(x) );

will output 1, not 2.

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

I think I disagree with mom. Dealing with restaurants, 15% is standard, plus or minus based on the service. What I dislike is 6 or more the tip is automatically added and calculated at 18%. I've even seen higher.

Other services have different rates. 15% is not universal.

This looks like a good writeup

More info here

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

Look at the characters.
If there is a digit, subtract '0' to make it a number and accumulate it into a variable -- details for you to work out.
If you get a /, next digits go into another variable.

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

Ship input for placement:
Enter each cell for the carrier? Sure, I want 1,2; 4,4; 2,3; 6,7 and 8,4
How about:
X,Y,Direction (1=up,2=down...) Then just place the ship specified in the locations. It's easier to test if the ship won't fit:

if (X - shipSize < 0) bad
if (X + shipSice > 10) bad

something like that.
And use the ship number, not a character. That way you know immediately which ship has been hit.

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

@WaltP , Our teacher teaching us from the basic and they told us to use such functions, i don't know any other function to use then these void main(void) and clrscr () & getch () , can you tell me which functions should i use istead of the functions above ?

Then you are being seriously mistaught. The last version of Turbo C was ver 4 in 1993. That's 17 years ago. Many compilers have been following the changes in the standards and the industry since then. Maybe you should ask your instructors why they insist on using such old tools when they have been surpassed by many free compilers since then.

Xufyan commented: u'r great :) +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How can we help if you don't tell us what the problem is.

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

I FIGURED IT OUT!!! Now to move on to the more complex ones!! Thanks anyways guys!!

Yay!!! Just take it somewhat slow. Remember the old programmer's proverb:
"If builders built buildings the way programmers wrote programs, the first woodpecker to come along could destroy civilization."

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

The array is 200,000 because the string can have up to 200,000 characters inputed in it.

Why? Read one character at a time. You need 1 character, not 200K.

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

That'll teach you to be enthusiastic... :icon_twisted:

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

"You have/are/using/used technology that's obsolete," doesn't signify your age; it is a fallacy.

True. You've obviously been to the C/C++ forums lately. :icon_twisted:

Ha ha ha phallus-y. Like it, like it.

Don't be such a d.... No, don't go there... :icon_wink: