Author Topic: Programing Help  (Read 5420 times)

0 Members and 2 Guests are viewing this topic.

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Programing Help
« on: May 07, 2013, 05:03:40 am »
Hey guys, so I recently started my Programing course, because I suck at it!
We are
designing a program that will allow a user to input a list of your family members along with their age and state residency. Once the data is inserted into the script, the average age of the entire family would need to be displayed to the user. Once the Age is displayed, the names of those who live in the state of Texas would be listed.

Below is what I got so far... can anyone help me get this finished up.

Quote
//Main Module - Declare Variables
Declare Names[50] As String
Declare Ages[50] As Integer
Declare State[50] As String
Declare MemberName, Residency As String
Declare MemberAge, Count As Integer
Declare AgeAvg As Float
Call Welcome_Message module
Call Input module
End Program

//Input module - request necessary inputs
Set Count = 0
Write "Enter a family member's name; Enter * when done."
Input MemberName
While MemberName != "*"
  Set Names[Count] = MemberName
  Write "Enter this family member's age: "
  Input MemberAge[Count]
  Set Ages[Count] = MemberAge
  Write "Enter this family member's state of residency: "
  Input Residency
  Set State[Count] = Residency
  Set Count = Count + 1
  Write "Enter a family member's name or * when done."
  Input MemberName
End While(MemberName)
Call Age_Average module
Call Texas_Residents module

//Age_Average module - This submodule will produce the average family age
//and display it to the user.
Declare Sum As Integer
Declare K As Integer
Set Sum = 0
Set K = 0
//The While loop below will get the sum of all ages
While K < Count
  Set Sum = Sum + Ages[K]
  Set K = K + 1
End While
//The below computes the age average and set its corresponding value to the variable.
Set AgeAvg = Sum/Count


//Texas_Residents module - This submodule will determine which family
//members reside in Texas and display their names.
If State == "Texas" Then
  Write "The following family members live in Texas: "
  Write Names[50]
Else
  Write "No family member lives in Texas."
End If
working on it...

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Programing Help
« Reply #1 on: May 07, 2013, 07:55:48 am »
You forgot to mention what language is this. The syntax is not familiar to me.

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #2 on: May 07, 2013, 05:21:16 pm »
It's really not a language at all, it is a pseudocode.
This is for a class I'm taking...
working on it...

Offline namespace7

  • Sir
  • ***
  • Posts: 561
  • Cookies: 115
  • My Brother's Keeper
    • View Profile
Re: Programing Help
« Reply #3 on: May 07, 2013, 07:55:58 pm »
I will help you to finish your program as soon as I finish all of my unfinished programs :D
"A programmer’s greatest enemy isn’t the tools or the boss or the artists or the design or the legacy code or the third party code or the API or the OS. A programmer’s greatest enemy is getting stuck.
Therefore a crucial step to becoming a better programmer is learning how to avoid getting stuck, to recognize when you’re stuck, and to get unstuck." -Jeff Wofford

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #4 on: May 07, 2013, 08:14:54 pm »
I will help you to finish your program as soon as I finish all of my unfinished programs :D

Hahahaha Okay... I shall wait :D in the meantime, if someone else has the time, that would be awesome.
working on it...

Offline Ragehottie

  • Knight
  • **
  • Posts: 313
  • Cookies: -9
  • Hack to learn, not learn to hack.
    • View Profile
Re: Programing Help
« Reply #5 on: May 07, 2013, 10:01:41 pm »
Do you want someone to code it? Or just help you finish it? or what? I dont understand at all
Blog: rexmckinnon.tumblr.com

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #6 on: May 09, 2013, 06:31:51 pm »
Do you want someone to code it? Or just help you finish it? or what? I dont understand at all

I need someone to help me finish it. I'm having a hard time figuring out how to get he information to display only those who live in the state of Texas.
working on it...

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #7 on: May 09, 2013, 08:15:02 pm »
you already keeping track of the count, use a for loop to compare the "state[count]" variable with the word "Texas" if it finds it then display the name variable "Names[Count]"

what language you will code in ?
« Last Edit: May 09, 2013, 08:16:33 pm by Rav3n »

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #8 on: May 09, 2013, 08:32:18 pm »
you already keeping track of the count, use a for loop to compare the "state[count]" variable with the word "Texas" if it finds it then display the name variable "Names[Count]"

what language you will code in ?

Rav3n, would the following be correct then?
Quote
For (State[Count] = 1; State[Count] == Texas; State[Count++])
  Write "The following family members live in Texas: "
  Write Names[Count]
End For

Well, this is my intro to programming, but if I get the time I will try to use Phyton or C+ so I can learn the language in the process.
working on it...

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #9 on: May 09, 2013, 08:39:42 pm »
You started the Count from "0"
 & let's say it's in C++

Code: [Select]
for ( int x = 0; x <= Count; x++ ) {
    if ( State[x] == "Texas" )
        cout << Names[x] << "\n";
}
so we use array to get the value
I'm still learning C++ so don't take this as absolute working code but i think the idea is ok :)

Note if you get error, the "<=" might needs to be "<"

Also, add and else statement in case there was no match like displaying No Result was Found or something like that.
 
« Last Edit: May 09, 2013, 09:02:22 pm by Rav3n »

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #10 on: May 09, 2013, 09:37:10 pm »
I went back to my textbook and I actually found my answer after some (okay, a lot of!!!) reading... I think the below will perform my task :D
Code: [Select]
Declare Index As Integer
Declare Found As Integer
Set Index = 0
Set Found = 0
While (Found == 0) AND (Index < Count)
  If State[Index] == "Texas" Then
    Set Found = 1
  End If
  Set Index = Index + 1
End While
If Found == 0 Then
  Write "No Family members reside in Texas."
Else
  Write "Following family members reside in Texas: "
  Write Names[Index - 1]
End If
working on it...

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #11 on: May 09, 2013, 10:20:19 pm »
but what if there was more than one person with state is set to "Texas" ?

I think your code will just display the last one found.
You can use the While statement instead of the for, but i think it won't be as you posted.

From what i have read; for statement is used when you know exactly when the loop ends, in this case when it exceeds the Counts number.
But The while loop used when you don't know when the loop ends.
« Last Edit: May 09, 2013, 10:23:51 pm by Rav3n »

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #12 on: May 09, 2013, 10:35:58 pm »
BTW, your code can work if you tweak it a bit.
Code: [Select]
Declare Index As Integer
Declare Found As Integer
Set Index = 0
Set Found = 0

While (Index < Count)
  If State[Index] == "Texas" Then
    Set Found = 1
    write Names[Index]
End While
If Found == 0 Then
  Write "No Family members reside in Texas."

The Found variable will be used to tell the last if statement to display no result msg if there was no match.

If you use if/else statement inside the while loop, the result will be like
Quote
No Family members reside in Texas.
No Family members reside in Texas.
KoubaK
No Family members reside in Texas.
Rav3n
it will display the message for every try.
« Last Edit: May 09, 2013, 10:36:36 pm by Rav3n »

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #13 on: May 09, 2013, 10:39:52 pm »
Rav3n, good point... Thanks
So if I apply a For loop instead of the While... this is what I have in mind.
Code: [Select]
Declare K As Integer
Set K = 0
For (K = 0; K < Count; K++)
  If State[K] == "Texas" Then
    Set Found = 1
  End If
  Set K = K + 1
End For

Now, if the above works... how I get the data to display?
Do I simply invoke " Names[K] " ???
working on it...

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #14 on: May 09, 2013, 10:51:24 pm »
yes, but must make it inside the for loop,
and there is no need for the found variable
instead of
Code: [Select]
set found = 1make it
Code: [Select]
write Names[k]

Also, you don't need to increment the K,
Code: [Select]
K = K + 1
The K++ do that for you ( in C++ of course )
« Last Edit: May 09, 2013, 10:53:23 pm by Rav3n »