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

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

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

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

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

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

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

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

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

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

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

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

Hijack thread? He never mentioned hijack thread. Hijacking has nothing to do with this thread except it deals with new members not bothering to follow rules.

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

i can get this to round up can anyone help? i have been using the ceil function but its not working right i get an error saying it cant be used as a function.
i put ceil b4 the ( in this formula below and i put ceil b4 the ( in the 2nd formula.

Are you unable to post the exact error? What does "not working right" mean? Why can't ceil be used?

You should know by now it's a waste of time to post questions without details because we just ask questions about stuff you didn't tell us. Then we have to wait for you. Hours and many posts later, you get an answer. Cut that time by figuring out what might help us understand and just explain the entire problem in one post. Errors and all.

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

if (teamScore ==1 && teamScore != -999) If team = 1 it can't be -999. Simplify both if statements

cout << "Team 1" << score1 = sum + numPoints;
cout << "Team 2" << score2 = sum + numPoints;

Did they both score the points? Once the output is done, what's the value of sum ? Is sum important?

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

Can anyone explain whats wrong with this program

void main(void) - see this clrscr (); - very old non-standard function that hasn't existed since 1986 getch (); - non-standard function that is very non-portable, works in very few compilers
and no formatting making the program hard to follow.

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

If I pass match[100] as an argument , doesn't that make it just the value at match[100]. I thought I the proper way to pass an array as a function argument was a match[]. I assumed this was a pointer to the first element and it could be modified accordingly. Was I wrong?

Yes, you were wrong.

(sub,match,100);

should work. match is the 'pointer'. match[] is defining it as an array, use in the function definition, not part of the executable code.

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

I don't see any writing to any file. You might want to open/write/close a file and you might get banana into the file.

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

VB6 is probably no longer available, but VB-Express 2008 can be downloaded from here

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

And I'm the second one to agree with FBody. Do you still think he's wrong?

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

scanf is often the source of input problems. as you can see, you have the most trivial example and it's already being problematic. since there are better alternatives readily available, you'll do well to learn to stop using it as soon as possible.

While you are bashing scanf() and gets() , might as well quote you with one minor change:

anyone who ever suggests that you use scanf("%s",) is also an idiot. this especially includes programming instructors. here is why.

:icon_wink:

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

i want to figure out a way other than a switch statement that will show the user how many gallons of paint are needed when the user says how many square feet they have.

If you don't want a switch statement, use a series of if statements.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
if(!inQuiz)//if file did not open correctly
	{
		cerr <<"File could not be opened." <<endl;
		exit(1);
	}

There is no reason to call a function to exit from main() . Just return 0;

inQuiz.seekg(0);//set position to begining of file

When you open a file you are at the beginning of the file. No need to seek.

inQuiz.seekg(1 - 1, ios::cur);
	inQuiz.getline(answer, sizeof(answer));
	inQuiz.seekg(1 - (sizeof(answer)), ios::cur);

Again, why do you have to seek? You read the answers and the name is read next. It's automatic. Seeking is only necessary when moving non-linearly through a file. You are making file reading way too complicated.

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

can anyone give me some hints on this im having issues

thanks

Biggest issue is not reading the rules and posting any information at all about what those issues are. We can answer specific questions, but if all you're going to do is talk in generalities, the only help we can give is writing it for you.

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

Do you have to deal with each value from 0 to 255 for each color?

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

Your first problem is that

Like I said most of it is still half written and Im still fidgitting with it.

Stop fidgitting with it. Take one task, write it. Test it. Perfect it. Then move to the next task.

I'd recommend starting with the display function. Write it completely first -- passing parameters so you can display either player's board.

Then write the ship placement function. Takes board, ship, starting position, and either the direction (up, left,...) or ending position.

Now the user input function, which calls the perfected ship placement function. Then modify the user input function to create the computer 'input' function.

Etc....

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

Did you read about strings like I mentioned? What else can I do for you. Write it myself, maybe?

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

If you know vectors, you certainly know how to read a string. If not, maybe you need to read your text about strings and input.

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

Read each word. Search for 'w' in the word. Pretty simple.

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

LOL!..its some assignment I have so not sure its a good thing to do posting my code...but from debugging this part of the code could potentially be the problem but still not sure..

char line[256];
FILE *fd = fopen("FILE.txt", "r");
while (1) {
        if (fgets(line, 256, fd) == NULL) {
                  break;
        } else {
                  // Do stuff...
        }

Did this happen to anyone?? or just me...

If FILE.txt does not exist, you continue into the read loop. Granted, based on this snippet, the if will error out, but still it's a bad practice.

And since we still don't really know what's happening, and you're not even sure if this code is the spot, we really can't help. We need details and code that exhibits the problem. Weed out everything you can until you're left with a short code segment that exhibits the error.

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

Sure. Line 235 is wrong. Don't use a pointer there....

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

I just decided to call the post as it was... I guess it caught on.

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

Read? Sound like from a file or user input. Or do you mean get the time from the system?

I really don't see the need to get both separately. Get them together and move the DATE into the date variable, move the TIME into the time variable.

I'm actually not sure if there are separate functions.

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

Move each character after the '0' one location down the array.

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

Why google for something they don't believe is a problem? Just because someone says don't is not enough of a reason.

Just sayin' :icon_wink:

And if that's why I'm here, why post at all if I'm just gonna have to clean up after you? I don't even clean up after my kids, and you're old enough to know better :icon_twisted:

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

What I would do is whether you find a solution or not, just keep looking.

IOW, when you find the first solution, save it in a file. Then just continue looking as if you didn't find a solution. Eventually, you should find them all.

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

You are the one that will need a lot of luck if you think it is acceptable to make use of fflush(stdin) and gets().
fflush() is undefined if you give it stdin as an argument.
gets() is not an option even for throw away code.
It would be better if you do not touch the keyboard at that point.

In other words, gets() and fflush().

It's good to give an explanation, not just tell people something and they just have to believe you. None of us have credibility to new posters.

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

#1) Use better variables: PswdIn, Pswd, Name, NameIn would be much better.

#2) Display the values before the IF statements to make sure they are the same.

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

Look at the MsgBoxStyle.xxx value from the parameters and show the buttons specified.

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

Use in-code documentation.
Pay closer attention to what you are doing.
Think before you type.
Remember your program's structure.
Take notes.

Take your pick.

Actually, pick them all. And heavy on think. That's what the brain does best.

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

But I am not able to understand that when I try to read from the file when the get pointer is at the last byte (or somwhere there) of the file then why does it read the last data element entry full. I meant that when the get pointer has already traversed the last entry then why is it travelling back a few bytes to read that again. Please explain???
And sorry for the late reply...

We don't care how late your reply was? We weren't waiting for it, believe me. :icon_wink:

See this about your .eof() question. feof() is identical to .eof().

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

Is there any way to make it so newbies and problem posters are blocked from posting until they either read/reread and sign off on rules page just like signing off on user agreement before continuing to install software.

When was the last time you actually read a user agreement? You can't actually force anyone to read the rules.

But if they need to sign off on them before posting as you suggest, at least we now have definite recourse to slap hands. They can't complain about being reprimanded.

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

above programme is right,

but you have to maintain the indentation in the programme.

After you posted that unformatted code in another thread you have the gall to mention indentation here? Practice what you preach.

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

But DaniWeb didn't exist in the 80's. Who would you hassle without us?
:icon_wink:

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

Note I used an if . Can you tell why you can't just do the replacement without the if ?

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

The array is not defined in the function definition correctly.
There is no way the compiler knows how big the array is using void descend(int arrayx[sizex][sizey], int sizex, int sizey) sizey in the array definition needs to be an explicit number, not a variable.