Problem with Statement

Compiler using Dev-C++

Learning programming from Book "Programming Principles and Practice Using C++"

I'm trying to get statement for such as 01 = January.
I get four errors.

Let me assure you, i'm a newbie! Can someone please explain what's wrong?
An example will greatly help. Thanks!

22,35 [Error] expected ';' before numeric constant
20,2 [Error] 'else' without a previous 'if'
16,19 [Error] expected ')' before numeric constant
16,6 [Error] 'month_number' was not declared in this scope

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  // change the numberic to string //

#include <std_lib_facilities.h>

int main()

{
	int month = 0;
	int month1 = 0;
	
	cout << "Please enter month of your birthday\n";
	
	cin >> month;
	cin >> month1;

	if (month_number 01 == month_string = "January";
	
		cout << "your month birthday is" << month << "\n";
		
	else;
	
		cout << "No birthday?" << month 1 << "\n";
		
}
Last edited on
Do not place semicolons after if or else lines, as that means to do nothing (just a semicolon is an empty statement). You are also:
* Have a strange condition for your if statement - what is this supposed to say?
* Missing a closing parentheses after your if
* Have an extra space on line 22 between month and 1
Last edited on
I'm sorry if I didn't explain clearly. What I'm trying to do is

if somebody type in command 01/23/1895

I want command prompt to rely

January/23/1895

I thought (if) would work on that

example
if (month 01 = January.

Edit:I had some tweaking it seem to be working better:

Please tell me if I need anything to improve. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <std_lib_facilities.h>




int main()



{
 	
 	int month = 0;
 	
 		std::cout << "Hello, please put in your birthday's month. In number form. \n";
 	
 		std::cin >> month;
 	
			if (01 == month) 
	
	cout << "The month of your birthday is: " << "January";

return 0;
 	
}


Last edited on
closed account (E0p9LyTq)
One possible, minimalist rewrite of the program could be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// change the numberic to string //

#include <std_lib_facilities.h>

int main()

{
   int month = 0;
   string month_string = "";

   cout << "Please enter month of your birthday (1-12)\n";

   cin >> month;

   if (month == 1)
   {
      month_string = "January";

      cout << "your month birthday is" << month_string << "\n";
   }
   else
   {
      cout << "No birthday?" << "\n";
   }

}


The code above compiled using Orwell's Dev-C++ 5.11.
Thanks! With your code/ I understood how to add for rest of months. Turn out my first mistake was == 0 and wrong place of if/else.
closed account (E0p9LyTq)
I would recommend using an array (vector) of strings to store the month names, and/or use a switch statement for getting the proper month name instead of using multiple if/then statements.
Topic archived. No new replies allowed.