I am writing a program for my C class that asks a user to input a month number and a day number. It determines if the number is within the parameters of 1-12 for months, and 1-31 for days.
I am using Dev C++ 4.9.9.2.
Here is my source code
/ Lab 04
Jenny Tmouh
COSC 1336
Due September 29, 2006/
/ This program asks the user
to enter a number for a
month between 1 and 12 and
a day between 1 and 31. If
the numbers do not fall in
the parameters, it will
display an error message.
If the user enters correct
numbers, the program will
print them back out./
When I run this program, it displays the month and day numbers as 2293616, instead of the numbers I entered.
Could someone tell me where my problem is? I have tried switching float with int, and I have also tried switching the %d with %f in all of the statements it shows up in.
Thank you for your help!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you tell the printf() function to expect an integer argument but provide no argument at all! It is just taking whatever happens to be on the stack at the expected location.
I bet you wished you had looked at your own code more closely before posting! ;-)
printf ("The month is %d.\n", month );
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am writing a program for my C class that asks a user to input a month number and a day number. It determines if the number is within the parameters of 1-12 for months, and 1-31 for days.
I am using Dev C++ 4.9.9.2.
Here is my source code
/ Lab 04
Jenny Tmouh
COSC 1336
Due September 29, 2006/
/ This program asks the user
to enter a number for a
month between 1 and 12 and
a day between 1 and 31. If
the numbers do not fall in
the parameters, it will
display an error message.
If the user enters correct
numbers, the program will
print them back out./
include <stdio.h>
include <stdlib.h>
main()
{
float month;
float day;
}
When I run this program, it displays the month and day numbers as 2293616, instead of the numbers I entered.
Could someone tell me where my problem is? I have tried switching float with int, and I have also tried switching the %d with %f in all of the statements it shows up in.
Thank you for your help!
Engage brain before posting!
Here:
> printf ("The month is %d.\n");
you tell the printf() function to expect an integer argument but provide no argument at all! It is just taking whatever happens to be on the stack at the expected location.
I bet you wished you had looked at your own code more closely before posting! ;-)
printf ("The month is %d.\n", month );
Clifford