problem

C

Charlton Wilbur

(quoting me)

KT> The traditional way to do that is to provide an obfuscated
KT> solution that satisfies the requirements, but that the student
KT> is unlikely to be able to understand or explain.

KT> Such an approach is arguably unfair to the student who might
KT> fall for it.

I'm not so charitable; the student is doing something he knows is
unethical in the first place, so if he submits a solution he does not
understand and gets caught, it's his own fault. Especially if other
posters have admonished the student to do his own howmework.

Charlton
 
C

Christopher Benson-Manica

Such an approach is arguably unfair to the student who might fall for
it.

"Let the cheater beware." It's no more unfair than it is to answer a
request for a term paper about thermodynamics with a document
consisting of that old "hell is exothermic" joke.
 
M

Martin Ambuhl

Dear sir,
I want to input an integer value from keyboard and display on screen
"WELL DONE" that many times, how can i do this.

Short of writing your code for you, there is little to say beyond what
you have already written. We won't do your homework. As a hint,
though, you should write a program that does the following:
1) read an integer value from the standard input stream
2) write "WELL DONE" that many time to the standard output stream
There are, of course, no such concepts of "screen" or "keyboard" in C,
which deals with streams.
 
C

Chris Hills

Keith Thompson said:
per9000 said:
In case no one replied. Here's a solution that works for me:
[code snipped]

Nobody else provided a solution for a very good reason. The original
poster was (apparently) asking us to do his homework for him.
Providing a complete solution on a silver platter doesn't do anybody
any favors.

Oh bugger.... I am going to have to fully agree with Keith :)

The only time it is acceptable to post code to this sort of question is
when it contains code the student clearly could not have done or does
something completely different.
 
A

Army1987

#include <stdio.h>

int main(int argc, char * argv[])
Why the hell isn't int main(void) ok here?
{
int number;
int counter;

printf("Enter number >> ");
What if stdin isn't flushed?
scanf("%d", &number);

What if I write "x" and hit return?
/* allow values 1-99 only */
if (number > 0 && number < 100)
for(counter = 0; counter < number; counter++)
Since you never use counter, and you never use number after the
loop, what's wrong with while(number-- /* > 0, but not needed here
since we know here number is positive */)?
printf("WELL DONE\n");
What's wrong with puts("WELL DONE")?
else
printf("bad number.");
Don't have a program producing output not ending with a newline.
return(0);
I would return EXIT_FAILURE in the "bad number" case. YMMV.
 
C

Chris Hills

Dear sir,
I want to input an integer value from keyboard and display on screen
"WELL DONE" that many times, how can i do this.

As I said in September 2005......


Hi to any students.

THIS is the model of how to ask for help with homework... Ask your
questions this way and you will get help!

>Ok so I have this class for C. I have to write this program for my
>instructor,

1: clearly saying it is a home work question.
Pretending is it not does not work here. You are also likely to get
answers that, it you use them, will make it obvious that you did not do
the work yourself.
> where he has already posted the softcopy and algorithm. But
>my question is I have to convert meters to feet and in this I have to
>output not only the feet but also the inches

2: clearly state the problem to be solved.
People here are not mind readers. I you can't take the time to properly
explain the problem then no one will take the time to answer.
>now I think I have coded
>the feet calculation properly but. I don't know how to send the
>remainder to inches and than recalculate it and display that
>calculation

3: clearly state what you are having a problem with. "It doesn't work"
or similar mean you are lazy and have not analysed the problem . Other
people will not either.

AND

> here is what I have coded this so far.
>
>#include <stdio.h>
>
>#define FACTOR 2.54
>
>int main (void)
>

4: Post your attempt at solving the problem.
No one is going to write code for you but if you have a go they will
point you in the write direction and suggest improvements or point out
the obvious errors

>and here is the page with my instructors algorithm
>http://www.gibson.vero-beach.fl.us/classes/cop2000/fall/prj02.html

5 any additional information.
If people don't get the same information you have one the problem they
could give you the correct answer to a different problem.
>sorry i cant explain this better i am just lost right now

6 Be polite. You are asking for help....


Full marks to Glitter Boy for this model question. This is why he has
got some serious and sensible help.

We should post his question to the FAQ as the model how to ask a
homework question.... though most students don't read it :-(
 
K

Keith Thompson

Army1987 said:
#include <stdio.h>

int main(int argc, char * argv[])
Why the hell isn't int main(void) ok here?

"int main(void)" is the hell ok here.

"int main(int argc, char * argv[])" is also the hell ok here.

It's not necessary to specify the parameters if you don't use them,
and it may trigger a warning for some compilers, but it's perfectly
the hell legal.
What if stdin isn't flushed?

I think you mean stdout.
What if I write "x" and hit return?

Good point.
Since you never use counter, and you never use number after the
loop, what's wrong with while(number-- /* > 0, but not needed here
since we know here number is positive */)?

Sure, that would work, but a for loop of the form:

for (i = 0; i < MAX; i ++)

is a very common idiom, and it makes it obvious that the body of the
loop will be executed exactly MAX times (assuming the body of the loop
doesn't do anything funny). If I saw your suggested "while (number--)
....", I'd have to take a moment to convince myself that it doesn't
execute number-1 or number+1 times.
What's wrong with puts("WELL DONE")?

Nothing. What's wrong with printf("WELL DONE\n")?

For beginning programmers, it's easier to introduce a single
general-purpose output function than to ask the student to keep track
of the confusing variety of output routines provided in <stdio.h>.
puts() may be more efficient than printf(), but I can almost guarantee
that the difference is insignificant. And some compilers will
translate printf("...\n") to puts("...").

Don't have a program producing output not ending with a newline.
Agreed.

I would return EXIT_FAILURE in the "bad number" case. YMMV.

Agreed, but it's not a big deal in an assignment like this.

For the most part, you seem to be offering alternatives, not
improvements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top