Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Recognizing a space
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tupacalypse_Vinsanity




PostPosted: Thu Oct 13, 2005 6:17 pm   Post subject: Recognizing a space

I need some help, the user enters a word and if its an odd amount of numbers itll output the middle letter and if its even itll output the 2 middle letters, but i dont know how to make it recognize spaces or if they enter 2 words how to output the middle letters of the 2 words.

code:


var letter : int := 0
var middle, middle1 : int
var word : string


put "Please enter a word"
get word
letter := length (word)
if letter / 2 = letter div 2 then
    middle := letter div 2
    middle1 := middle + 1
    word := word (middle) + word (middle + 1)
    put word
else
    middle := letter div 2 + 1
    word := word (middle)
    put word
end if
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Oct 13, 2005 6:47 pm   Post subject: (No subject)

I explain searching for a space in the String Manipulation tutorial.
Tupacalypse_Vinsanity




PostPosted: Sat Oct 15, 2005 6:45 pm   Post subject: Well

I read over yours and im still having some trouble, can you clarify some points please?
Cervantes




PostPosted: Sat Oct 15, 2005 6:57 pm   Post subject: Re: Well

Tupacalypse_Vinsanity wrote:
can you clarify some points please?

Sure. What points?
Tupacalypse_Vinsanity




PostPosted: Sat Oct 15, 2005 8:02 pm   Post subject: Well

I know how to make the program recognize a space but my problem now is that if they input more than 2 words, the middle letter might be a space, and i dont know how to get it to tell them the middle letter is a space, can you help? It also might be easier if we chatted over MSN, i added you a few days ago but i dont know if you have been on or you just didn't accept. My email is tupacalypse.now@gmail.com

also here you can look at my code, i added alot of things lol:

code:
%Tyrell Cromoshuk
%Tues, Oct 11, 2005
%The user enters a word and it outputs the middle letter(s) depending on the size of the word(even or odd amount of chars)

import GUI in "%oot/lib/GUI"

var winID : int
winID := Window.Open ("position:top;center,graphics:640;480")

%-------------------------------------------------Variable Table--------------------------------------------------------
var letter : int := 0
var middle, middle1 : int
var word : string
var introscreen, layout1, layout2, layout3 : int
var key, key1, key2 : string (1)
var font1 : int
%---------------------------------------------------End of Table--------------------------------------------------------

%Allows the quit button to work
procedure Quit
    Pic.Draw (layout3, 0, 0, picCopy)
    delay (4000)
    Window.Close (winID)
end Quit

%Fonts
font1 := Font.New ("Times New Roman:16")

%Layouts for the program
introscreen := Pic.FileNew ("c:/Warmup4IntroScreen.jpg")
layout1 := Pic.FileNew ("c:/Warmup4WordScreen.jpg")
layout2 := Pic.FileNew ("c:/Warmup4MiddleScreen.jpg")
layout3 := Pic.FileNew ("c:/Warmup4ClosingScreen.jpg")

procedure restart
    %Draws the intro screen for the program
    View.Set ("nocursor")
    Pic.Draw (introscreen, 0, 0, picCopy)
    locate (23, 2)
    getch (key)
    cls

    %Draws the next screen and asks the user to input a word
    Pic.Draw (layout1, 0, 0, picCopy)
    locate (11, 39)
    get word : *
    letter := length (word)
    if letter / 2 = letter div 2 then
        middle := letter div 2
        middle1 := middle + 1
        word := word (middle) + word (middle + 1)
        Font.Draw ("Even", 355, 134, font1, red)
        getch (key1)
        cls
    else
        middle := letter div 2 + 1
        word := word (middle)
        Font.Draw ("Odd", 355, 134, font1, red)
        getch (key1)
        cls
    end if

    %Draws the next screen and gets the user to decide what they want to do next
    Pic.Draw (layout2, 0, 0, picCopy)
    Font.Draw (word, 355, 280, font1, red)

    %Creates the buttons
    var b : int := GUI.CreateButton (25, 270, 0, " Restart", restart)
    var quitButton := GUI.CreateButton (25, 230, 0, "Quit!", Quit)
    loop
        exit when GUI.ProcessEvent
    end loop
end restart

restart
Cervantes




PostPosted: Sat Oct 15, 2005 8:08 pm   Post subject: Re: Well

Tupacalypse_Vinsanity wrote:
Ithe middle letter might be a space, and i dont know how to get it to tell them the middle letter is a space, can you help?

Why not just output "The middle letter is a space."?
code:

put "The middle letter is " ..
if middle_letter = " " then
    put "a space."
else
    put middle_letter
end if


Tupacalypse_Vinsanity wrote:

It also might be easier if we chatted over MSN, i added you a few days ago but i dont know if you have been on or you just didn't accept. My email is tupacalypse.now@gmail.com

I rarely go on MSN. You've got a much better chance at catching me on CompSci.ca's IRC channel. Server: AfterNET. Channel: #compsci.ca
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: