User Profile

Collapse

Profile Sidebar

Collapse
heiro1
heiro1
Last Activity: May 10 '13, 05:50 PM
Joined: Jan 23 '13
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • heiro1
    replied to Method syntax producing error
    in Ruby
    nvm figured it out. Thx anyway!!
    See more | Go to post

    Leave a comment:


  • heiro1
    started a topic Method syntax producing error
    in Ruby

    Method syntax producing error

    I am learning Ruby using codecademy and the current exercise tells the user to :

    Define two methods in the editor:

    A greeter method that takes a single string parameter, name, and returns a string greeting that person. (Make sure to use return and don't use print or puts.)

    A by_three? method that takes a single integer parameter, number, and returns true if that number is evenly divisible by three and...
    See more | Go to post

  • heiro1
    replied to printing a redacted word in an if loop
    in Ruby
    I found the answer already but thank you if you were about to post something helpful!

    Code:
    puts "Whats your input brah?"
    text = gets.chomp
    puts "Whatchu are you hiding bro?"
    redact = gets.chomp
    words = text.split(" ")
    words.each {|x| if x == redact then print "REDACTED"+" " else print "#{x}"+" " end}
    See more | Go to post

    Leave a comment:


  • heiro1
    replied to printing a redacted word in an if loop
    in Ruby
    This code definitely works if I use "do" instead of the curly braces. I tested it. The tutorial I am using said that those two are the same thing and can be used inter-changably but as I found, it doesn't work when I use curly brackets. Unless I am missing something important.
    See more | Go to post

    Leave a comment:


  • heiro1
    started a topic printing a redacted word in an if loop
    in Ruby

    printing a redacted word in an if loop

    My code won't print "REDACTED" in place of the redact variable. I do not know why though. Can anyone shed some light? I appreciate it! Here is my code :

    Code:
    puts "Whats your input brah?"
    text = gets.chomp
    puts "Whatchu are you hiding bro?"
    redact = gets.chomp
    words = text.split(" ")
    words.each {|x| if x == redact print "REDACTED"+" " else print x+"
    ...
    See more | Go to post
    Last edited by heiro1; Apr 25 '13, 06:00 PM. Reason: I tired another approach but still experiencing the same problem

  • heiro1
    started a topic Largest element in array, variable query
    in C

    Largest element in array, variable query

    Hello All,

    I was curious as to why the for loop in the example below, starts col = 1 instead of col = 0. Are they doing that just for this example because the largest value is stored in column 0 (the first column)? Also, I don't understand why the inequality sign is < instead of > because I am looking at it like:

    If the largest value > the current value being evaluated in a particular iteration, then the largest...
    See more | Go to post

  • heiro1
    replied to Trouble understanding a shift calculation
    in C
    I can't connect how "shift" is implemented in this particular program.

    This is a start:

    I need to map the letters 'A' through 'Z' (assuming only uppercase letters) to the integers 0 through 25.

    n = c - 'A';

    Now I perform the shift with modulus arithmetic:

    n = (n + shift) % 26;

    Finally map back to a letter:

    p = n + 'A';

    but can anyone...
    See more | Go to post

    Leave a comment:


  • heiro1
    replied to Trouble understanding a shift calculation
    in C
    I think if I shift a character by a shift amount the character may or may not be out of bounds:

    'a' + 3 is 'd' ok,

    'x' + 3 is '{' not ok.

    So if the character is over 'z' take away 26, if under 'a' add 26. can be a usable function.

    However, can someone please explain to me how the shift is calculated in the program and is applied it to the file? It has me totally stumped :(
    See more | Go to post

    Leave a comment:


  • heiro1
    started a topic Trouble understanding a shift calculation
    in C

    Trouble understanding a shift calculation

    Hey all!

    I was going over this code to read a file on my desktop that decrypts a cesar cipher code and I am stuck trying to figure out how the shift is calculated in this program.

    From what I can tell, Max e's is the shifted letter with the highest frequency. Since e's are the most common letter in English, the program is trying to set the highest frequency char in the cipher, to an 'e' in English. Which is good, as far...
    See more | Go to post
    Last edited by heiro1; Mar 12 '13, 10:39 PM. Reason: Being more concise

  • Oh, well it didn't effect my calculations in any way but you are correct of course. I overlooked that part thanks for the correction
    See more | Go to post

    Leave a comment:


  • Thanks friend! What I ended up doing was on line 16, I changed 0 to 1 because 0 is not prime. Then, I added (double) to line 70. Lastly, I made b =1. That did the trick. Thanks for the tips! I left set precision in there because it did make my columns look neater :)
    See more | Go to post

    Leave a comment:


  • heiro1
    started a topic Prime Number chilliad program calculation adjustment?
    in C

    Prime Number chilliad program calculation adjustment?

    Hi Guys!
    I was wondering if someone could give me a quick tweak. I just finished my chilliad program. It calculates the primes and average number of primes. However, when I look at my answer and the teacher's answer, I seem to be off by like a smidgen.

    She has:

    Total primes in the first 50 chiliads: 5133
    Average number per chiliad: 102.66

    I have:

    Total primes in the first...
    See more | Go to post

  • Ok, wow, thank you so much for that! You just put it into perfect perspective for me!! I appreciate it!
    See more | Go to post

    Leave a comment:


  • Ok, I'm processing that..
    See more | Go to post

    Leave a comment:


  • My book wasn't clear on whether or not rand was assigned to be between 1-6 or not. So, I assumed the function had to come to 1-5(+ 1) on its own.
    See more | Go to post

    Leave a comment:


  • So, does rand() % 6 know to return a value of 1-5 in the first place? 1-5 is supposed to be the result (plus one of course). I mean, 6 / 32767 = 5461.16 +1 = 5462 true, but how does this function then, take the number 5462 and spit out 1-5 (plus 1)? That is the crux of my confusion.
    See more | Go to post

    Leave a comment:


  • Hi There,
    Thanks for your reply! I am currently taking math95 along with CS161 so a modulus being a part of regular math is news to me. I never heard of it until mt CS161 class.

    Anyway, although you pointed that out, I am still left with my original question. It sounds like you basically misunderstood it, that's not a hard thing to do considering I did a poor job trying to articulating my concern in the first place. I'll try to...
    See more | Go to post

    Leave a comment:


  • heiro1
    started a topic Calculating the formula of a dice roll using rand?
    in C

    Calculating the formula of a dice roll using rand?

    Hi Guys!

    So, I am using the modulus and a rand as part of a function I am writing. Now, I understand that:

    Code:
    rand() % 6 + 1;
    gives me a random number between one and six in this situation. However, I also know that

    Code:
    rand();
    gives me a random value from 0 - 32767 and
    Code:
    srand;
    changes the sequence

    but I thought...

    % = Whatever the remainder of a is after a / b.

    ... So, if you...
    See more | Go to post
    Last edited by heiro1; Feb 18 '13, 05:40 AM. Reason: I needed to make the question more clear

  • heiro1
    started a topic Arithmetic using a for loop
    in C

    Arithmetic using a for loop

    Hello Everyone,
    One thing that I was not able to fully understand even though I read through the section on it a few times, is the for loop. I mean, I understand the premise of (statement, condition, update statement). However, I do not quite understand how a math problem is affected by this.

    Can someone clarify with a simple example of how this works using multiplication and division? I would really appreciate it!
    ...
    See more | Go to post

  • heiro1
    replied to Data File input sorting question
    in C
    Ok problem solved, here is my result. It works like a charm:

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    
    using namespace std; 
    
    int main()
    {
        //Declare variables to manipulate data
        string name;
        string fileSource;
        
        int maleScore = 0;
        int femScore = 0;
        int unScore
    ...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...