Helpp plaaa

General chit chat, chin wag, abuse, etc.
No-1
Loyal fan
Posts: 291
Joined: Sun Sep 12, 2004 5:57 am
Location: tdy

Post by No-1 »

I have a test coming up next week and the question is like this:
a)Write a program to display the following two prompts:
i)Enter a month (use a1 for Jan, etc)
ii)Enter a day of the month

Have your program accept and store a number in the variable month in response to the first prompy, and accept and store a number in the variable day in response to the second prompt. If the month entered is not between 1 and 12 inclusive, print a message informing the user that an invalid month has been entered. If the day entered is not between 1 and 31, print a message informing the user that an invalid day has been entered.

This is my first exam i'm starting in sem1 currently. I'm really lost any code snippets will be much apprecited or a plain explanation on starting is ok. I dont expect the whole answer
Support Outpost@HBTop50<br><a href='http://hbtop50.berserkvision.com/in.php?id=582' target='_blank'>Outpost@HBTop50</a><br>
Sprint
Spamtastic
Posts: 1000
Joined: Tue Jun 06, 2006 6:59 am
Location: Far from home
Contact:

Post by Sprint »

No-1 wrote: I have a test coming up next week and the question is like this:
a)Write a program to display the following two prompts:
i)Enter a month (use a1 for Jan, etc)
ii)Enter a day of the month

Have your program accept and store a number in the variable month in response to the first prompy, and accept and store a number in the variable day in response to the second prompt. If the month entered is not between 1 and 12 inclusive, print a message informing the user that an invalid month has been entered. If the day entered is not between 1 and 31, print a message informing the user that an invalid day has been entered.

This is my first exam i'm starting in sem1 currently. I'm really lost any code snippets will be much apprecited or a plain explanation on starting is ok. I dont expect the whole answer
Do u have visual studio? (2000 or better)
Because theres ready tools for that sort of thing, or is it cheating :P?
<span style='color:blue'><span style='font-size:19pt;line-height:100%'><u><b>FUCK Helbreath!</b></u></span></span><br><br><span style='color:gray'><a href='http://www2.analystica.com/users/anttu/online/ngd' target='_blank'>ngdnetwork</a> OFFICIAL WEBSITE OF Northern Game Developers. Do visit! (THEY ARE UP!)<br><a href='http://project3d.x.am' target='_blank'>Project3d development forum</a> plz join and discuss,develop,give ideas,feedback. Anything goes as long it helps the project!</span><br><br>Zepto Znote 6625WD: 1.8Ghz dual core, 2GB, 512mb graphics card(dedicated), 160GB HDD<br><img src='http://www.signaturebar.com/uploads/images/10111.jpg' border='0' alt='user posted image' /><br><img src='http://www.signaturebar.com/uploads/images/13229.jpg' border='0' alt='user posted image' /><br><img src='http://www.signaturebar.com/uploads/images/8852.png' border='0' alt='user posted image' />
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

1. What lang should this be written in?
2. Is this to be handed in or written under test conditions?
3. How much will you pay?

Naw just fucking around with the 3rd question haha. 1st semester I'm guessing Java for some friendly OO.
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
tester
Outpost bitch
Posts: 544
Joined: Wed Jan 07, 2004 8:58 pm

Post by tester »

C java or VB

its just the basic if clauses, u should rly try those lol :) if u dont know those ur fked xD


Cheers Tester
I support a woman's right to choose<br><br>- In the Mouth?<br>- In the Ass ?<br>- In the Vagina?<br>- Between the Tits?
charlie
Outpost4lyfe
Posts: 3324
Joined: Sun Apr 06, 2003 12:24 am
Location: Mt GOD
Contact:

Post by charlie »

<?

if(isset($submit)){
if ($_POST['month'] =< 12 && $_POST['month'] => 1){
$month = $_POST['month'];
}else{
echo 'Invalid Month';
}

if ($_POST['day'] =< 12 && $_POST['day'] => 1){
$month = $_POST['day'];
}else{
echo 'Invalid day';
}
}

?>
<form method="post" action="index.php">
Month<textarea rows="1" cols="2" wrap="physcial" name="month"><br>
Day<textarea rows="1" cols="2" wrap="physcial" name="day">
<input type="submit" name="submit" value="Submit">
</form>

there php script im drunk enjoy :P
Girlfriends are dedicated hookers.
Sprint
Spamtastic
Posts: 1000
Joined: Tue Jun 06, 2006 6:59 am
Location: Far from home
Contact:

Post by Sprint »

lol charlie
<span style='color:blue'><span style='font-size:19pt;line-height:100%'><u><b>FUCK Helbreath!</b></u></span></span><br><br><span style='color:gray'><a href='http://www2.analystica.com/users/anttu/online/ngd' target='_blank'>ngdnetwork</a> OFFICIAL WEBSITE OF Northern Game Developers. Do visit! (THEY ARE UP!)<br><a href='http://project3d.x.am' target='_blank'>Project3d development forum</a> plz join and discuss,develop,give ideas,feedback. Anything goes as long it helps the project!</span><br><br>Zepto Znote 6625WD: 1.8Ghz dual core, 2GB, 512mb graphics card(dedicated), 160GB HDD<br><img src='http://www.signaturebar.com/uploads/images/10111.jpg' border='0' alt='user posted image' /><br><img src='http://www.signaturebar.com/uploads/images/13229.jpg' border='0' alt='user posted image' /><br><img src='http://www.signaturebar.com/uploads/images/8852.png' border='0' alt='user posted image' />
No-1
Loyal fan
Posts: 291
Joined: Sun Sep 12, 2004 5:57 am
Location: tdy

Post by No-1 »

it must be written in c++ cin cout bla bla bla..helpp
Support Outpost@HBTop50<br><a href='http://hbtop50.berserkvision.com/in.php?id=582' target='_blank'>Outpost@HBTop50</a><br>
Charles
Loyal fan
Posts: 418
Joined: Wed Nov 26, 2003 8:20 pm

Post by Charles »

No-1 wrote: it must be written in c++ cin cout bla bla bla..helpp
so you want it to tell you what month/day you entered? like if you enter 1 then hit enter it tells you January for the month etc? just making sure lol
<i>"Always write good code. Feel bad to write bad code."</i>
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

You didn't specify much so i just basically copied charlie's in C++ using cin/cout.

If you keep entering invalid numbers then the input will loop untill you enter the correct value. Just dont enter characters as input coz i don't remember how to quick fix that on consoles lol. Jimmy will probably know how if he browses this topic.

Code: Select all

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
	int iMonth, iDay;
	cout << "Input the Month: ";
	cin >> iMonth;
	while(iMonth < 1 || iMonth > 12)
	{
  cout << "Invalid input! The Month must be between 1~12\n";
  cout << "Input the Month: ";
  cin >> iMonth;
	}
	cout << "Input the Day: ";
	cin >> iDay;
	while(iDay < 1 || iDay > 31)
	{
  cout << "Invalid input! The Day must be between 1~31\n";
  cout << "Input the Day: ";
  cin >> iDay;
	}
	system("PAUSE");
	return 0;
}
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
No-1
Loyal fan
Posts: 291
Joined: Sun Sep 12, 2004 5:57 am
Location: tdy

Post by No-1 »

Heck i don't even know what the teacher wants. I'll go get an explanation but guys i haven't learn to use the command while or system("PAUSE") or <cstdlib> so far its <iostream> and <cmath> and the commands to use is cout cin if else if and stuff like that
Support Outpost@HBTop50<br><a href='http://hbtop50.berserkvision.com/in.php?id=582' target='_blank'>Outpost@HBTop50</a><br>
No-1
Loyal fan
Posts: 291
Joined: Sun Sep 12, 2004 5:57 am
Location: tdy

Post by No-1 »

Opps double post shit..
Support Outpost@HBTop50<br><a href='http://hbtop50.berserkvision.com/in.php?id=582' target='_blank'>Outpost@HBTop50</a><br>
No-1
Loyal fan
Posts: 291
Joined: Sun Sep 12, 2004 5:57 am
Location: tdy

Post by No-1 »

Sry triple post
Support Outpost@HBTop50<br><a href='http://hbtop50.berserkvision.com/in.php?id=582' target='_blank'>Outpost@HBTop50</a><br>
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

No-1 wrote: Heck i don't even know what the teacher wants. I'll go get an explanation but guys i haven't learn to use the command while or system("PAUSE") or <cstdlib> so far its <iostream> and <cmath> and the commands to use is cout cin if else if and stuff like that
While is just a loop. The condition is the same as an if statement, it's selectional can be either true or false.
while(condition == true) <----
{
    ... // contents
}
If its true then the contents of the loop is ran(like an if statement). Here where it changes, when the loop finishes it goes back to the top and checks the condition again. See what i mean by loop? And also how it's a while? When it gets to checking the condition again if it's false the loop will be skipped(like an if statement). Any tutorial on the net will teach you this in more detail within 5~10min. Take a look at this in the actual code and you should see how it works though.

About cstdlib and system("pause"), all they are used for is to pause the console. Remove them both and put another "cin" in the place of system("pause"). Just make it anything it's only there to hault the program for user input before it returns 0 (aka exits). If i was your teacher i think based on your experience i'd pass that.
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
No-1
Loyal fan
Posts: 291
Joined: Sun Sep 12, 2004 5:57 am
Location: tdy

Post by No-1 »

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int iMonth, January;
January = 1;

cout << "Enter the Month: ";
cin >> iMonth;
if (iMonth < 1 || iMonth > 12)
cout << "The month has the be between 1~12!\n";
cout << "Enter the Month: ";
cin >> iMonth;
system ("PAUSE");
return 0;
}

How come when i do this it wont keep repeating to enter a number between 1~12 instead just close?
Anyway how can i make it say You've enter January if i enter 1
Support Outpost@HBTop50<br><a href='http://hbtop50.berserkvision.com/in.php?id=582' target='_blank'>Outpost@HBTop50</a><br>
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

No-1 wrote:How come when i do this it wont keep repeating to enter a number between 1~12 instead just close?
Because you're not using the while loop anymore. That loop checked if the input was bad and would continue looping intill the user enters valid numbers. Your code there just checks it once.
No-1 wrote:how can i make it say You've enter January if i enter 1
Cheap but it works lol.

Code: Select all

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
	int iMonth, iDay;

	cout << "Input the Month: ";
	cin >> iMonth;
	while(iMonth < 1 || iMonth > 12)
	{
  cout << "Invalid input! The Month must be between 1~12" << endl;
  cout << "Input the Month: ";
  cin >> iMonth;
	}

	cout << "Input the Day: ";
	cin >> iDay;
	while(iDay < 1 || iDay > 31)
	{
  cout << "Invalid input! The Day must be between 1~31" << endl;
  cout << "Input the Day: ";
  cin >> iDay;
	}
	
	cout << "You entered: " << iDay;
	switch(iDay)
	{
	case 1:
	case 21:
	case 31:
  cout << "st of ";
  break;
	case 2:
	case 22:
  cout << "nd of ";
  break;
	case 3:
	case 23:
  cout << "rd of ";
  break;
	default:
  cout << "th of ";
  break;
	}

	switch(iMonth)
	{
	case 1:
  cout << "January" << endl;
  break;
	case 2:
  cout << "February" << endl;
  break;
	case 3:
  cout << "March" << endl;
  break;
	case 4:
  cout << "April" << endl;
  break;
	case 5:
  cout << "May" << endl;
  break;
	case 6:
  cout << "June" << endl;
  break;
	case 7:
  cout << "July" << endl;
  break;
	case 8:
  cout << "August" << endl;
  break;
	case 9:
  cout << "September" << endl;
  break;
	case 10:
  cout << "October" << endl;
  break;
	case 11:
  cout << "November" << endl;
  break;
	case 12:
  cout << "December" << endl;
  break;
	}
	system("PAUSE");
	return 0;
}
<!--QuoteBegin-output+--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (output)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->Input the Month: 12
Input the Day: 22
You entered: 22nd of December
Press any key to continue . . .[/quote]
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
Post Reply