Hello:

I am having a bit of problem with logic in a segment (marked in blue) of this code: the indicated code should simply update the variable upon each pass of the function as it runs; the variable value maxes out at 456-- it will not increase by 228 beyond this point of the function's run.

I have not been able to determine why this is.

Any help is very appreciated. Thank-you in advance.

sharky_machine

Look.cpp

#include <cstdlib> 
#include <iostream>
#include "Look.h"
using namespace std;

int currPos = 0;
int checkFlag = 0;
static int shipPos1 = 0; // default start position (pos 0)                                
int shipPos2 = 228;

// 3.80 minutes (228 seconds) 

Look::Look() {
}
 
Look::~Look() {
}

void Look::printShipPos() 
{ 
       [B][B] if (checkFlag > 1) {
        shipPos = shipPos2 + 228; 
        cout << shipPos << endl;[/B][/B]
                           }
        {    
if (shipPos = 228) {
   std::cout << "French Polynesia [Out of Transmission Range]"<< endl; 
}
else if ((shipPos > 228) && (shipPos < 456)){
  std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl; 
}
else if ((shipPos >= 456) && (shipPos < 684)){
   std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl; 
}

[B].
.
.[/B]

//---------------------counter for fly-over access
checkFlag++; 
cout <<checkFlag<< endl;

return;    
        }
}

Recommended Answers

All 4 Replies

I beleive you wanted to update the static variable shipPos1 instead of the variable shipPos which I don't see defined anywhere.

commented: ty +1

WolfPack:

Thank-you for your reply and for pointing out my now obvious mistake.

sharky_machine

commented: wc +5

Knock knock... do I see somthing missing...

#include <cstdlib> 
#include <iostream>
#include "Look.h"
using namespace std;

int currPos = 0;
int checkFlag = 0;
static int shipPos1 = 0; // default start position (pos 0)                                
int shipPos2 = 228;

// 3.80 minutes (228 seconds) 

Look::Look() {
}

Look::~Look() {
}

void Look::printShipPos() 
{ 
      if (checkFlag > 1) {
        shipPos = shipPos2 + 228; 
        cout << shipPos << endl;
                           }
        {    
// ouch
if (shipPos = 228) {
   std::cout << "French Polynesia [Out of Transmission Range]"<< endl; 
}
else if ((shipPos > 228) && (shipPos < 456)){
  std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl; 
}
else if ((shipPos >= 456) && (shipPos < 684)){
   std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl; 
}

.
.
.

//---------------------counter for fly-over access
checkFlag++; 
cout <<checkFlag<< endl;

return;    
        }
}

Knock knock... do I see somthing missing...

#include <cstdlib> 
#include <iostream>
#include "Look.h"
using namespace std;

int currPos = 0;
int checkFlag = 0;
static int shipPos1 = 0; // default start position (pos 0)                                
int shipPos2 = 228;

// 3.80 minutes (228 seconds) 

Look::Look() {
}
 
Look::~Look() {
}

void Look::printShipPos() 
{ 
         if (checkFlag > 1) {
        shipPos = shipPos2 + 228; 
        cout << shipPos << endl;
                           }
        {    
// ouch
 if (shipPos = 228) {
   std::cout << "French Polynesia [Out of Transmission Range]"<< endl; 
}
else if ((shipPos > 228) && (shipPos < 456)){
  std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl; 
}
else if ((shipPos >= 456) && (shipPos < 684)){
   std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl; 
}

[B].
.
.[/B]

//---------------------counter for fly-over access
checkFlag++; 
cout <<checkFlag<< endl;

return;    
        }
}

~S.O.S.~ :

Yes, missing "=" in "==" -- thank-you for pointing this out to me.

sharkey_machine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.