Quantcast

Maximum PC

It is currently Sat Dec 20, 2014 2:43 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Help with an extrmely simple program...
PostPosted: Wed Dec 29, 2004 9:07 am 
Willamette
Willamette
User avatar

Joined: Wed Dec 08, 2004 12:53 pm
Posts: 1242
Location: in trouble
Hey, I'm making a little program that asks you your name last name age and gender.

It works great up until it asks me my gender so i say "male" and it says something went wrong. here is the porgram actually running:


Code:
Enter your first name:
Rafael
Hello,Rafael, what is your last name?
Lopez
So your full name is Rafael Lopez? Great, Now how old are you?
13
Are you male or female?
male
./mysecond~: line 20: syntax error: unexpected end of file
[rafael@localhost Desktop]$


oh bummer.

and here is what I made

Code:
#!/bin/bash
clear
echo " "
echo "Enter your first name:"
read FirstName
echo "Hello,"$FirstName", what is your last name?"
read LastName
echo "So your full name is "$FirstName" "$LastName"? Great, Now how old are you?"
read age
echo "Are you male or female?"
read gender
if "male"
   then
      echo "Mr. "$LastName" is "$age" years old. Cool. Bye!"
if "female"
   then
      echo "Mrs. "$LastName" is "$age" years old. Cool. Bye!"

exit


what am I doing wrong?

I have also tried no putting echoes in the "if male/female then ..." but nothing changes.

Help please?


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 9:42 am 
Willamette
Willamette
User avatar

Joined: Wed Dec 08, 2004 12:53 pm
Posts: 1242
Location: in trouble
UPDATE

spidermonkey helped me now the code looks like:

Code:
#!/bin/bash
clear
echo " "
echo "Enter your first name:"
read FirstName
echo "Hello,"$FirstName", what is your last name?"
read LastName
echo "So your full name is "$FirstName" "$LastName"? Great, Now how old are you?"
read age
echo "Are you male or female?"
read gender
if [ male ];
    then
       echo "Mr. "$LastName" is "$age" years old. Cool. Bye!"
else [ female ]
       echo "Mrs. "$LastName" is "$age" years old. Cool. Bye!"
fi
exit


The problem is that weather i say im female or male it still says "Mr........." and not "Mrs......."


Top
  Profile  
 
 Post subject: Re: Help with an extrmely simple program...
PostPosted: Wed Dec 29, 2004 9:43 am 
I'd rather be modding!
I'd rather be modding!
User avatar

Joined: Fri Jun 25, 2004 3:47 pm
Posts: 3731
Location: Las Vegas
ATI4EVER! wrote:
Hey, I'm making a little program that asks you your name last name age and gender.

It works great up until it asks me my gender so i say "male" and it says something went wrong. here is the porgram actually running:


Code:
Enter your first name:
Rafael
Hello,Rafael, what is your last name?
Lopez
So your full name is Rafael Lopez? Great, Now how old are you?
13
Are you male or female?
male
./mysecond~: line 20: syntax error: unexpected end of file
[rafael@localhost Desktop]$


oh bummer.

and here is what I made

Code:
#!/bin/bash
clear
echo " "
echo "Enter your first name:"
read FirstName
echo "Hello,"$FirstName", what is your last name?"
read LastName
echo "So your full name is "$FirstName" "$LastName"? Great, Now how old are you?"
read age
echo "Are you male or female?"
read gender
if "male"
   then
      echo "Mr. "$LastName" is "$age" years old. Cool. Bye!"
if "female"
   then
      echo "Mrs. "$LastName" is "$age" years old. Cool. Bye!"

exit


what am I doing wrong?

I have also tried no putting echoes in the "if male/female then ..." but nothing changes.

Help please?


Shouldn't it be something like 'if gender = "male"'

Manta


Top
  Profile  
 
 Post subject: Re: Help with an extrmely simple program...
PostPosted: Wed Dec 29, 2004 9:46 am 
Monkey Federation (Top 10)*
Monkey Federation (Top 10)*
User avatar

Joined: Thu Jun 24, 2004 1:22 pm
Posts: 27395
Location: In a cage, dumbass.
MantaBase wrote:

Shouldn't it be something like 'if gender = "male"'

Manta


That is what I just told him.

But only ... [ "gender" = "male" ];

So far we got the code to work, but the IF THEN statement is still goofy


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 9:50 am 
Willamette
Willamette
User avatar

Joined: Wed Dec 08, 2004 12:53 pm
Posts: 1242
Location: in trouble
this code makes both female and male (in the conole when i run it) show up as Mr. and not female as Mrs.

Code:
#!/bin/bash
clear
echo " "
echo "Enter your first name:"
read FirstName
echo "Hello,"$FirstName", what is your last name?"
read LastName
echo "So your full name is "$FirstName" "$LastName"? Great, Now how old are you?"
read age
echo "Are you male or female?"
read gender
if [ $gender=male ];
    then
       echo "Mr. "$LastName" is "$age" years old. Cool. Bye!"
else [ $gender=female ];
       echo "Mrs. "$LastName" is "$age" years old. Cool. Bye!"
fi
exit


[ male ] [ gender=male ] and [ $gender=male] all do teh same thing/


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 9:54 am 
Monkey Federation (Top 10)*
Monkey Federation (Top 10)*
User avatar

Joined: Thu Jun 24, 2004 1:22 pm
Posts: 27395
Location: In a cage, dumbass.
ATI4EVER! wrote:
[ male ] [ gender=male ] and [ $gender=male] all do teh same thing/


Read your messanger. lol I said try [ "$gender" = "male" ], not [ gender=male ] or [ $gender=male].


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 10:07 am 
Willamette
Willamette
User avatar

Joined: Wed Dec 08, 2004 12:53 pm
Posts: 1242
Location: in trouble
well taht didnt work either.

I also have Linux Programming for dummies but that is not helping me right now...


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 10:12 am 
Monkey Federation (Top 10)*
Monkey Federation (Top 10)*
User avatar

Joined: Thu Jun 24, 2004 1:22 pm
Posts: 27395
Location: In a cage, dumbass.
Mission accomplished. Just need to clean up the code a little. Attention to detail is very important in programming.

#!/bin/bash
clear
echo " "
echo "Enter your first name:"
read FirstName
echo "Hello,"$FirstName", what is your last name?"
read LastName
echo "So your full name is "$FirstName" "$LastName"? Great, Now how old are you?"
read age
echo "Are you male or female?"
read gender
if [ "$gender" = "male" ];
then
echo "Mr. "$LastName" is "$age" years old. Cool. Bye!"
elif [ "$gender" = "female" ];
then
echo "Mrs. "$LastName" is "$age" years old. Cool. Bye!"
fi
exit


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.