Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 11th, 2004, 5:05 PM   #21
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Oct 11th, 2004, 5:17 PM   #22
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,649
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
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;
}
and here is mine for the same program and what i did i will point out in comments
#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.
big_k105 is offline   Reply With Quote
Old Oct 11th, 2004, 5:23 PM   #23
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road


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.
TecBrain is offline   Reply With Quote
Old Oct 11th, 2004, 5:25 PM   #24
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,649
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
no problem and then i fixed another little error where you had
month = "September";
when it was suppose to be
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.
big_k105 is offline   Reply With Quote
Old Oct 11th, 2004, 5:34 PM   #25
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Oct 11th, 2004, 5:36 PM   #26
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 555
Rep Power: 5 Benoit is on a distinguished road
#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
Benoit is offline   Reply With Quote
Old Oct 11th, 2004, 5:40 PM   #27
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Oct 12th, 2004, 3:57 AM   #28
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Old Oct 12th, 2004, 7:57 AM   #29
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 555
Rep Power: 5 Benoit is on a distinguished road
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
Benoit is offline   Reply With Quote
Old Oct 12th, 2004, 2:58 PM   #30
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
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.
TecBrain is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC