Greetings:
A simple question that has me stuck: Program runs, calls function, function runs... Return to Main? This last area is where it fails. No errors, just no control returned to Main.cpp at end of function run. I've been studying the code much and researching the solution on the Net all day.
I swear there is one (1) too many "}" in Look.cpp, but it is not detected by the compiler. (?)
Any point in the right direction would be vastly appreciated-- I do not want the answer given to me directly at this point, I want to figure it out myself. Perhaps just a hint, a link to a relevant Web resource, etc?
Thank-you in advance, everyone.
Look.h
class Look {
public:
float shipPos ;
float satPos;
float interior;
void printShipPos(); // new function declaration
Look();
~Look();
};
Main.cpp
#include <iostream>
#include "Look.h"
using namespace std;
int choice;
int main()
{
std::cout << "________________________________"<< endl;
std::cout << ""<< endl;
std::cout << "Welcome to Platform XYZ-- Please Enter a Number:"<< endl;
std::cout << ""<< endl;
std::cout << "[1]Check Location for Transmission to Base"<< endl;
std::cout << "[2]Stub"<< endl;
std::cout << ""<< endl;
std::cout << "________________________________"<< endl;
cin >> choice;
Look look1; //** ERROR
if(choice == 1){
look1.printShipPos(); //** ERROR
}
else {
std::cout << "OTHER! chosen (stub)"<< endl;
}
system("PAUSE");
return 0;
}
Look.cpp
#include <ctime>
#include <cstdlib>
#include <iostream>
#include "Look.h"
using namespace std;
int countFlag = 0;
Look::Look() {
}
Look::~Look() {
}
void Look::printShipPos()
{
srand((unsigned)time(0)); //RNG
float shipPos;
for(int index=0; index<1; index++){
shipPos = (rand()%24)+7;
cout << shipPos << endl;
countFlag = 1; //test
cout << countFlag << endl; //test
if (shipPos <= 3.80) {
std::cout << "French Polynesia [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 7.60) {
std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 11.40) {
std::cout << "Pacific Ocean (open waters) [Out of Transmission Range] 4320 miles from Tampa, Florida"<< endl;
}
else if ((shipPos >= 15.20) && (shipPos < 19.00)) {
std::cout << "Pacific Ocean (open waters) [In Transmission Range] 3240 miles from Tampa, Florida"<< endl;
}
else if ((shipPos >= 19.00) && (shipPos < 22.80)){
std::cout << "La Paz, Baja, Mexico [In Transmission Range]"<< endl;
}
else if ((shipPos >= 22.80) && (shipPos < 26.60)){
std::cout << "Gulf of Mexico [In Transmission Range]"<< endl;
}
else if ((shipPos >= 26.60) && (shipPos < 30.40)){
std::cout << "Tampa, Florida [In Transmission Range]"<< endl;
}
else if ((shipPos >= 30.40) && (shipPos < 34.20)){
std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 4320 miles from Lisbon, Portugal"<< endl;
}
else if ((shipPos >= 34.20) && (shipPos < 38.00)){
std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 3240 miles from Lisbon, Portugal"<< endl;
}
else if (shipPos <= 38.00) {
std::cout << "Atlantic Ocean (open waters) [In Transmission Range] 2160 miles from Lisbon, Portugal"<< endl;
}
else if (shipPos <= 41.80) {
std::cout << "Canary Islands [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 45.60) {
std::cout << "Lisbon, Portugal [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 49.40) {
std::cout << "Tripoli, Libya [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 53.20) {
std::cout << "Baghdad, Iraq [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 57.00) {
std::cout << "Eastern Iran [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 60.80) {
std::cout << "Central Tajikistan [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 64.60) {
std::cout << "Kathmandu, Nepal [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 68.40) {
std::cout << "Hanoi, Vietnam [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 72.20) {
std::cout << "Hong Kong, China [Out of Transmission Range]"<< endl;
}
else if (shipPos <= 76.00) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 5400 miles from French Polynesia"<< endl;
}
else if (shipPos <= 79.80) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 4320 miles from French Polynesia"<< endl;
}
else if (shipPos <= 83.60) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 3240 miles from French Polynesia"<< endl;
}
else if (shipPos <= 87.40) {
std::cout << "Pacific (open waters) [Out of Transmission Range] 2160 miles from French Polynesia"<< endl;
}
else{
std::cout << "Pacific (open waters) [Out of Transmission Range] 1080 miles from French Polynesia"<< endl;
}
return ;
}
}