Author Topic: Programing Help  (Read 5418 times)

0 Members and 1 Guest are viewing this topic.

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #15 on: May 09, 2013, 10:58:06 pm »
Rav3n, so it should look something like this:
Code: [Select]
Declare K As Integer
Set K = 0
For (K = 0; K < Count; K++)
  If State[K] == "Texas" Then
    Write Names[K]
  Else
    Write "No family members reside in Texas."
  End If
End For
 
« Last Edit: May 09, 2013, 10:59:00 pm by KoubaK »
working on it...

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #16 on: May 09, 2013, 11:01:29 pm »
in pesudo code .. yes, but don't use else statement or you will end with the result i posted before.

In C++ , inside The for statement you can declare the variable and assign it to a value inside the for command.



Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Programing Help
« Reply #17 on: May 09, 2013, 11:02:28 pm »
Rav3n, so it should look something like this:
Code: [Select]
Declare K As Integer
Set K = 0
For (K = 0; K < Count; K++)
  If State[K] == "Texas" Then
    Write Names[K]
  Else
    Write "No family members reside in Texas."
  End If
End For
 

No, that will still be wrong. Should look like this:
Code: [Select]
Declare K As Integer
Declare atLeastOnePrinted as boolean
Set atLeastOnePrinted = false
Set K = 0
For (K = 0; K < Count; K++)
  If State[K] == "Texas" Then
    Write Names[K]
    Set atLeastOnePrinted = true
  End If
End For

If !atLeastOnePrinted then
    Write "No family members reside in Texas."
end if
 


Code: (cpp) [Select]
bool atLeastOnePrinted = FALSE;
for(int i=0;i<=sizeof(States);i++)
{
    if(States[i] == "Texas") {
        cout << "Person: " << Names[i] << " lives in Texas." << endl;
        atLeastOnePrinted = TRUE;
    }
}
if(!atLeastOnePrinted)
    cout << "No family members reside in Texas." << endl;
« Last Edit: May 09, 2013, 11:06:30 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #18 on: May 09, 2013, 11:15:23 pm »
ande, since I cannot use a boolean (just because it has not been covered in class yet).
would introducing Found back into the pseudo work?
Code: [Select]
Declare K As Integer
Declare Found As Integer
Set Found = 0
Set K = 0
For (K = 0; K < Count; K++)
  If State[K] == "Texas" Then
    Write Names[K]
    Set Found = 1
  End If
End For

If Found == 0 then
    Write "No family members reside in Texas."
end if
working on it...

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Programing Help
« Reply #19 on: May 09, 2013, 11:18:07 pm »
ande, since I cannot use a boolean (just because it has not been covered in class yet).
would introducing Found back into the pseudo work?
Code: [Select]
Declare K As Integer
Declare Found As Integer
Set Found = 0
Set K = 0
For (K = 0; K < Count; K++)
  If State[K] == "Texas" Then
    Write Names[K]
    Set Found = 1
  End If
End For

If Found == 0 then
    Write "No family members reside in Texas."
end if

Yes, that would work just fine :) Basically a boolean is 1 and 0, true and false.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Rav3n

  • Serf
  • *
  • Posts: 30
  • Cookies: 5
    • View Profile
Re: Programing Help
« Reply #20 on: May 09, 2013, 11:22:12 pm »
just replace
Code: [Select]
bool atLeastOnePrinted = FALSE;with
Code: [Select]
int atLeastOnePrinted = 0;

And
Code: [Select]
atLeastOnePrinted = True;with

Code: [Select]
atLeastOnePrinted = 1;
And
Code: [Select]
if(!atLeastOnePrinted)
    cout << "No family members reside in Texas." << endl;
with
Code: [Select]
if(atLeastOnePrinted == 1)

    cout << "No family members reside in Texas." << endl;
In ande's Code

Offline KoubaK

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 2
  • Burlao
    • View Profile
Re: Programing Help
« Reply #21 on: May 09, 2013, 11:27:28 pm »
Thanks guys... Once I'm done with my other classes I will use the free time to try to actually code the entire program.
working on it...