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

Username:   Password: 
 RegisterRegister   
 How can I have non-case sensitive input?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asdfasdf123




PostPosted: Wed Jan 21, 2015 12:04 pm   Post subject: How can I have non-case sensitive input?

What is it you are trying to achieve?
I'm trying to make a survey program to prepare for my compsci final exam.


What is the problem you are having?
The program requires non-case sensitive input, which I have no clue how to program.


Describe what you have tried to solve this problem
I've tried editing the if statements to have more options (see code below) and looking up answers


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


var hand, topHand1, topHandTotal : string
var income, topIncome, totalRightIncome, totalLeftIncome, totalIncome, prevIncome, num, leftNum, rightNum : int
var rightAvg, leftAvg, avgIncome : real
totalRightIncome := 0
totalLeftIncome := 0
totalIncome := 0
num := 0
leftNum := 0
rightNum := 0

put " " : 25, "Welcome to the Income Survey"
put ""

loop
    num := num + 1
    put "Are you left handed or right handed? " ..
    get hand
    if hand = "right" or hand = "Right" then
        put "You are right handed."
    elsif hand = "left" or hand = "Left" then
        put "You are left handed."
    end if
    exit when hand = "done"
    put "Please enter your income: $" ..
    get income
    totalIncome := totalIncome + income
    if hand = "right" then
        totalRightIncome := totalRightIncome + income
        rightNum := rightNum + 1
    elsif hand = "left" then
        totalLeftIncome := totalLeftIncome + income
        leftNum := leftNum + 1
    end if
    put ""
    if num = 2 then
        if income > prevIncome then
            topHand1 := hand
            topIncome := income
        elsif num > 2 then
            if income > prevIncome and income > topIncome then
                topHand1 := hand
                topIncome := income
            end if
        end if
    end if
    prevIncome := income
end loop

leftAvg := totalLeftIncome / leftNum
rightAvg := totalRightIncome / rightNum
avgIncome := totalIncome / num
if totalLeftIncome > totalRightIncome then
    topHandTotal := "left"
elsif totalRightIncome > totalLeftIncome then
    topHandTotal := "right"
end if

put ""
put "Summary for the given data"
put "Average income of left handed people: $", leftAvg
put "Average income of right handed people: $", rightAvg
put "A ", topHand1, " handed person makes the most, earning $", topIncome
put "On average, ", topHandTotal, " handed people earn more money"
put "Thank you for using the Income Survey Program"



Please specify what version of Turing you are using
4.1 1.0.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jan 21, 2015 12:51 pm   Post subject: RE:How can I have non-case sensitive input?

The easiest method is to convert all input to either lower or upper case before checking it. Loop over every character, and if it's the wrong case, change it to upper or lower. Then do your comparisons as normal.
bubb4h0t3p




PostPosted: Thu Jan 22, 2015 7:33 pm   Post subject: Re: RE:How can I have non-case sensitive input?

Insectoid @ Wed Jan 21, 2015 12:51 pm wrote:
The easiest method is to convert all input to either lower or upper case before checking it. Loop over every character, and if it's the wrong case, change it to upper or lower. Then do your comparisons as normal.

also the commands for doing this are
Turing:
Str.Upper("string you want to convert")

for converting it all to upper case or
Turing:
Str.Lower("string you want to convert")

for converting it all to lower case.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: