No, you make some pseudo code for what you want to do and translate it into real C code, whether or not that includes isdigit.
Beginners won't learn if you throw the spoon to them. They must learn to get it themselves.
In other words, don't tell them how to logically do something! They must use their own logic to come to this conclusion!
It's alright to explain functions do and introduce new functions to help with a specific task, but logic must never be handed out! This is a very critical part of programming and it is essential that every programmer out there knows it like the back of their hands!
I actually appreciate you guys not giving me the direct answer.
But I've run into another error and I just don't see what I'm doing wrong. I tried to simplify the program without using isdigit (because I don't even see why it's necessary in this program) but I'm still getting an error...but much less errors.
error: too few arguments to funtion 'time'
EDIT: When I remove the header #include <time.h> the program runs BUT as soon as it runs a Microsoft Window pops up and says "Guessing Game.exe has stopped working".Code:#include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <time.h> int main() { int iResponse = 0; int iAnswer = 0; srand(time()); iAnswer = (rand() % 10) + 1; printf("Guessing Game\n"); printf("\nGuess a number from 1 to 10: "); scanf("%d", &iResponse); if (iResponse < 1 || iResponse > 10) { printf("Enter a number between 1 and 10"); } else { if (iResponse == iAnswer) { printf("\nYou guessed right!\n"); } else { printf("\nSorry, you guessed wrong\n"); printf("The correct guess was %d\n", iAnswer); } } }
Any ideas?
Last edited by pmacdonald; 07-11-2009 at 07:10 PM.
EDIT:
Alright so I was playing around with the program more and decided to start eliminating lines until the program worked. When I took off the following line:
srand(time());
the program ran. But as you guys know now the answer isn't really random. It should still produce different numbers from 1 to 10 because of the following:
iAnswer = (rand() % 10) + 1;
but it doesn't even do that...each time I run the program iAnswer = 2.
Any help would be greatly appreciated.
I did look it up...and I know what it does. But for some reason it wasn't working in the program. Why don't you tell me why?
If you don't know why it wasn't working, then you didn't look it up.
Because, if you had looked it up, you would have seen this:
and you wouldn't have asked the question.Code:time_t time(time_t *tloc); The time() function returns the value of time in seconds since 0 hours, 0 minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, without including leap seconds. If an error occurs, time() returns the value (time_t)-1. The return value is also stored in *tloc, provided that tloc is non-null.
What we're really wondering, is why this is difficult for you to figure out:Do you know that 'time' is in your program?error: too few arguments to funtion 'time'
Do you know what an 'argument' is?
Do you know what 'too few' means?
Which part is confusing?
Quzah.
Hope is the first step on the road to disappointment.
>> I did look it up...and I know what it does. But for some reason it wasn't working in the program. Why don't you tell me why?
One rule of programming is to be sure to read the documentation on any function you plan to use. You'll need to know what arguments it takes, the constraints on the arguments, and what it returns. Had you looked up the docs on time you would have found that it takes a pointer to a time_t. Thus the error "too few arguments to function 'time'". Here's what my docs say:
Header File
time.h
Category
Time and Date Routines
Syntax
#include <time.h>
time_t time(time_t *timer);
Description
Gets time of day.
time gives the current time, in seconds, elapsed since 00:00:00 GMT, January 1, 1970, and stores that value in the location pointed to by timer, provided that timer is not a NULL pointer.
Return Value
time returns the elapsed time in seconds.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
What I don't understand is why in this book do they not give you all the correct information before asking you a question where you need said information. Going off the examples in the book the program I wrote should've worked...they didn't use any other header except #include <stdio.h> and #include <ctype.h>.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I'm going to start over with this program and start with writing out the pseudo code. I'll get back to you guys with my new results tomorrow (well I guess that would be later today).
>> I'm going to start over with this program and start with writing out the pseudo code.
Always a good idea. It usually helps clarify your ideas, anyway. Good luck.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }