![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Yeah, but I have to do it using case or if statements.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#22 |
|
PFO Founder
![]() ![]() |
here is your code
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int date;
int month;
int year;
char mon;
cout << "Please Enter the date(EX: 1 or 2)" << endl;
cin >> date;
cout << "Please Enter the month(EX 1 or 2)" << endl;
cin >> month;
cout << "Pleae Enter the year(2004 or 2003)" << endl;
cin >> year;
if (month = 1)
mon = "January";
else if ( month = 2)
mon = "February";
else if ( month = 3)
mon = "March";
else if ( month = 4 )
mon = "April";
else if ( month = 5 )
mon = "May";
else if ( month = 6)
mon = "June";
else if ( month = 7 )
mon = "July";
else if ( month = 8 )
mon = "August";
else if ( month = 9 )
month = "September";
else if ( month = 10 )
mon = "October";
else if ( month = 11)
mon = "November";
else if ( month = 12)
mon = "December";
cout << date << "/" << mon << "/" << year;
system("PAUSE");
return 0;
}![]() #include <iostream>
#include <stdlib.h>
#include <string> // added the include of string
using namespace std;
int main()
{
int date;
int month;
int year;
string mon; // changed mon to string
cout << "Please Enter the date(EX: 1 or 2)" << endl;
cin >> date;
cout << "Please Enter the month(EX 1 or 2)" << endl;
cin >> month;
cout << "Pleae Enter the year(2004 or 2003)" << endl;
cin >> year;
// changed all the = to ==
if (month == 1)
mon = "January";
else if ( month == 2)
mon = "February";
else if ( month == 3)
mon = "March";
else if ( month == 4 )
mon = "April";
else if ( month == 5 )
mon = "May";
else if ( month == 6)
mon = "June";
else if ( month == 7 )
mon = "July";
else if ( month == 8 )
mon = "August";
else if ( month == 9 )
mon = "September"; // changed month to mon, look up in your code at this line you will see what i mean :)
else if ( month == 10 )
mon = "October";
else if ( month == 11)
mon = "November";
else if ( month == 12)
mon = "December";
cout << date << "/" << mon << "/" << year << endl;
system("PAUSE");
return 0;
}^^ this code works perfectly you only had a few errors ![]()
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#23 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Thanks allot big_k105, I see the differences. so what you did is,...mmm taking the value which is string."..." to mon. I got it. ![]()
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#24 |
|
PFO Founder
![]() ![]() |
no problem and then i fixed another little error where you had
month = "September"; mon = "September";
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#25 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
yeah i saw it...
Thanks.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#26 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 555
Rep Power: 5
![]() |
#include<stdio.h>
#include<stdlib.h>
main()
{
char month[][12]={"Janary", "Febuary", "March", "April","June","July","september","October","November","December"};
int day,year,i;
scanf("%d %d %d",&day,&i,&year);
printf("\n%d/%s/%d\n",day,month[i-1],year);
system("PAUSE");
return 0;
}
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#27 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
I'll keep that on mind Benoit.
Thanks.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#28 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Ok guys, what if I want to add an if statement before that to check for the date value:
if ( date == 1) dat = "1st"; else if ( date == 2) dat = "2nd"; else if (date == 3) dat = "3rd"; But it seems if I add this before // check for valid month if (month == 1) mon = "January"; else if ( month == 2) mon = "February"; else if ( month == 3) mon = "March"; else if ( month == 4 ) mon = "April"; else if . . . . it wont work, I know that in VB6 you can add if and close the if as well, how can i do that with C++? in VB6 if date = 1 then .... end if if month = 1 then ..... end if how can i do that.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
|
|
#29 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 555
Rep Power: 5
![]() |
if(date==1)
{ do this stuff } Remember that you use == whe comparing You can also put && (and) and || (or) statements instead of doing an if statement for every date if(date==1 || date==21 || date==31) { printf("%dst",date); }
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#30 |
|
Hobbyist Programmer
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5
![]() |
Thanks Benoit. I worked it out.
__________________
Personal Portfolio TecBrain Support Forum Linux VS Windows ... Dont Even Think of it .. Distribution: Slackware if (OS==Linux) return success There are 10 kinds of people, those who can read binary numbers and those who can't. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|