Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 07-15-2014, 09:21 PM   #1
Baseband Member
 
Join Date: Jul 2014
Location: USA
Posts: 29
Default Visual logic help

Write a program that inputs a number between 1 and 1000 and displays the number with the appropriate two-letter ending. I have been working on this problem for two days now and am getting nowhere. This is what need to do
FOR 1 to 1000
if the second-last character is 1 (Numbers 10-19) ad "th"
For all others if last character is 1 add "st"
Last character 2 add "nd"
Last Character 3 add "rd"
And for all others add "th"
I am at a loss of figuring out how to input it the information in a way that the program will understand, please help!
__________________

megan1989 is offline   Reply With Quote
Old 07-17-2014, 04:09 AM   #2
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: Visual logic help

Have you got any code at all?

Much of your pseudo-code there, such as the loop, translates pretty directly into a statement for most languages. What language are you working with?
__________________

__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 07-17-2014, 10:46 AM   #3
Fully Optimized
 
strollin's Avatar
 
Join Date: Mar 2011
Location: USA
Posts: 1,938
Default Re: Visual logic help

I'm guessing the thread title should have said Visual BASIC help, not Visual logic.

If you post your code attempt we can make suggestions on how to get it working but we're not going to write the code for you.
strollin is offline   Reply With Quote
Old 07-17-2014, 10:53 AM   #4
Fully Optimized
 
jmacavali's Avatar
 
Join Date: Jun 2009
Posts: 4,867
Default Re: Visual logic help

Quote:
Originally Posted by strollin View Post
If you post your code attempt we can make suggestions on how to get it working but we're not going to write the code for you.
Bet they found another forum that did it for them...
__________________
****************************************
Don't take life too seriously -- no one gets out alive. Plus, who wants to arrive to the hereafter in pristine condition wearing a suit and tie?
I want to slide in sideways, worn out, used up, hair a mess, clothes tattered, & screaming, "Whooo! What a ride!"
****************************************
jmacavali is offline   Reply With Quote
Old 07-17-2014, 10:58 AM   #5
..m.0,0.m..
Site Team
 
iPwn's Avatar
 
Join Date: May 2010
Location: USA
Posts: 3,870
Default Re: Visual logic help

Welcome to CF!

As strollin pointed out, are you talking about Visual Basic? I've used Visual Logic before in school, but there's no real "writing" code in that... It's more GUI based. If that's the case though, post a screen shot so it jars my memory on what's available.

You could do something like:

Code:
string numberVarString = "What you're returning"; 
for(int x = 1; x <= 1000; x++) {
  if(x < 11) {
     numberVarString = x;
     continue; //Just sends to next iteration of loop
  else if(x < 20) {
        numberVarString = x + "th";
        continue;
   }
   else if(x < 100) {
       if(x.Substring(1,1) == 1))
           numberVarString = x + "st";
       else if(x.Substring(1,1) == 2))
           numberVarString = x + "nd";
       else if(x.Substring(1,1) == 3))
           numberVarString = x + "rd";
       else
           numberVarString = x + "th";
     }
   else if(x < 1000)
      //Repeat logic, but increase substring position (x.SubString(2,1))
}
That's a very short and incomplete answer, but knowing what you're using will help that.

EDIT: The above is C# code, just trying to demonstrate the nested logic statements that evaluate each iteration by groupings.
__________________
Me: You'd think as the dominant species we wouldn't be so effing stupid.
J: We're just intelligent enough to be completely effing stupid.
iPwn is offline   Reply With Quote
Old 07-17-2014, 12:29 PM   #6
Baseband Member
 
Join Date: Jul 2014
Location: USA
Posts: 29
Default Re: Visual logic help

Quote:
Originally Posted by strollin View Post
I'm guessing the thread title should have said Visual BASIC help, not Visual logic.

If you post your code attempt we can make suggestions on how to get it working but we're not going to write the code for you.
Yes, probably should have titled it that, I labeled it that because that is the program I am working with. Anyway this is how my problem looks now, and as you could tell I am probably doing in an extremely weird roundabout way, I am a beginner in learning how to work with the program.

Input: Number
Breakdown: Number MOD 10
IF STATEMENT: Breakdown>3 if true> Output: "Value is"&Number&"th"
if false: another IF> Breakdown=1>if true Output: "Value is" & Number&"st"
if false:Another IF>Breakdown=2>If true Output: "Value is"&Number&"nd"
and finally if false>Output: "Value is" &Number&"rd"

Like I said pretty screwed up and it doesn't account for the numbers like 11, 12, 13.
I am using visual logic 2.2.10, I hope that this can help clear up what I am having the problem with. As far as having the previous phrases I had in my initial post working well in the code there, I am not sure what statement I need to use for that i.e. FOR, WHILE, etc.
megan1989 is offline   Reply With Quote
Old 07-17-2014, 01:04 PM   #7
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: Visual logic help

Quote:
Originally Posted by megan1989 View Post
Yes, probably should have titled it that, I labeled it that because that is the program I am working with. Anyway this is how my problem looks now, and as you could tell I am probably doing in an extremely weird roundabout way, I am a beginner in learning how to work with the program.

Input: Number
Breakdown: Number MOD 10
IF STATEMENT: Breakdown>3 if true> Output: "Value is"&Number&"th"
if false: another IF> Breakdown=1>if true Output: "Value is" & Number&"st"
if false:Another IF>Breakdown=2>If true Output: "Value is"&Number&"nd"
and finally if false>Output: "Value is" &Number&"rd"

Like I said pretty screwed up and it doesn't account for the numbers like 11, 12, 13.
I am using visual logic 2.2.10, I hope that this can help clear up what I am having the problem with. As far as having the previous phrases I had in my initial post working well in the code there, I am not sure what statement I need to use for that i.e. FOR, WHILE, etc.
A for loop would be the normal loop of choice for incrementing one integer a set amount of times - there should be plenty of example on that online if you look around.

Ok, so sounds like one problem you have is getting the last digit of the number. There's two ways I can think of for doing this, the one I'd prefer would be to use mod. Mod is a % symbol and gives you the remainder (as in 150%2 would give you 0, 121%3 would give you 1.)

So to get the last digit, you can simply do a mod 10 (since whatever the remainder is after dividing the number by 10 will always be the last digit of the number.)

From there, you can apply your if statements to that number as you describe above
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 07-17-2014, 01:28 PM   #8
Baseband Member
 
Join Date: Jul 2014
Location: USA
Posts: 29
Default Re: Visual logic help

This may sound really stupid, but someone told me the only stupid question are the ones you don't ask. Aren't I making use of the mod already i.e. Number MOD 10, and for number such that end in 0, like 10 it doesn't give me the correct ending, it will loop through my IFs and give me 10rd. And it will not give the correct ending for numbers that there second last digit is 1 i.e 11, 12, 13. It will display for those number 11st, 12nd, 13rd. Maybe I'm not understanding something?
megan1989 is offline   Reply With Quote
Old 07-17-2014, 01:30 PM   #9
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: Visual logic help

Quote:
Originally Posted by megan1989 View Post
This may sound really stupid, but someone told me the only stupid question are the ones you don't ask. Aren't I making use of the mod already i.e. Number MOD 10, and for number such that end in 0, like 10 it doesn't give me the correct ending, it will loop through my IFs and give me 10rd. And it will not give the correct ending for numbers that there second last digit is 1 i.e 11, 12, 13. It will display for those number 11st, 12nd, 13rd. Maybe I'm not understanding something?
Doh, sorry, so you are. My mistake entirely.

The reason it won't work in that case is because 10 mod 10 will give you 0 (since it divides into itself exactly, with no remainder) - and that isn't covered in any of your if statements. So it'll fall through to the else case and go with the value specified there, which is "rd". Try adding a separate case in for 0
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 07-17-2014, 01:45 PM   #10
Baseband Member
 
Join Date: Jul 2014
Location: USA
Posts: 29
Default Re: Visual logic help

Alrightly then, it looks like that is going to work just fine. As for the exceptions like 11,12 and 13 I think I am going to input a IF statement using the OR before the Number MOD 10 with an EXIT loop to account for those numbers. It will look something like this

(Number <13) OR (Number >11) etc for all the number that are like that. Thank you so much it really helped me understand the visual logic program better
__________________

megan1989 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 10:40 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0