| | |
Compiling Problems
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2005
Posts: 175
Reputation:
Solved Threads: 0
Can't get this to compile for some reason. Anyone have an idea what's going on with it?
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> #include <iomanip.h> #include <time.h> void MoveT(int *tortoisePtr, const int End_race); void MoveHare(int *harePtr, const int End_race); void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race); int main() { const int End_race=70; int tortoise=1,hare=1,timer=0; cout<<"BANG!!!"<<endl; cout<<"AND THEY'RE OFF !!!!"<<endl; srand(time(NULL)); while(tortoise != End_race && hare != End_race) { MoveT(&tortoise,End_race); MoveHare(&hare,End_race); PrintCurrentPosition(&tortoise,&hare,End_race); timer++; } if(&tortoise>=&hare) cout<<"tortoise wins: "; else cout<<"hare wins: "; cout<<timer<<endl; return 0; } void MoveT(int *tortoisePtr, const int End_race) { int ranNum; ranNum = (rand()%10)+1 ; if(ranNum>=1 && ranNum<=5) *tortoisePtr += 3; else if(ranNum == 6 || ranNum == 7) *tortoisePtr -= 6; else *tortoisePtr += 1; if (*tortoisePtr<1) *tortoisePtr=1; else if(*tortoisePtr>End_race) *tortoisePtr=End_race; } void MoveHare(int *harePtr, const int End_race) { int hrandNum; hrandNum= (rand()%10)+1; if(hrandNum ==3 || hrandNum ==4) *harePtr +=9; else if(*harePtr==5) *harePtr -=12; else if(hrandNum>=6 && hrandNum<=8) *harePtr +=1; else if(hrandNum>8) *harePtr -=2; if(*harePtr<1) *harePtr=1; else if(*harePtr>End_race) *harePtr=End_race; cout<<endl; } void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race) { if(*snapperPtr == *bunnyPtr) cout<<setw(*bunnyPtr)<<"OUCH!!"; else if(*snapperPtr<*bunnyPtr) { cout<<setw(*bunnyPtr)<<'H'; cout<<setw(*snapperPtr-*bunnyPtr)<<'T'; } else { cout<<setw(*snapperPtr)<<'T'; cout<<setw(*bunnyPtr-*snapperPtr)<<'H'<<endl; cout<<endl; } } }
•
•
•
•
Originally Posted by kahaj
Can't get this to compile for some reason. Anyone have an idea what's going on with it?
} at the end of the file. "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jul 2005
Posts: 1,674
Reputation:
Solved Threads: 261
comment out one function at a time until you get back to a spot where it does compile. The last item you commented out probably has the error. Once you've found the function that's giving you trouble comment it all out to an empty body and start adding back one line/activity at a time to see what line is the likely culprit. As it stands I see several possible problems, but they should result in run time errors, not prevent compiling. Learning how to debug is as important as learning how to write code in the first place. Good luck.
•
•
Join Date: Sep 2005
Posts: 175
Reputation:
Solved Threads: 0
Okay, I cleaned up the code a bit and am still getting a compile error. Here's the code.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <stdlib> #include <iomanip> #include <time> void MoveT(int *tortoisePtr, const int End_race); void MoveHare(int *harePtr, const int End_race); void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race); int main() { const int End_race=70; int tortoise=1,hare=1,timer=0; cout << "BANG!!!" << endl; cout << "AND THEY'RE OFF !!!!" << endl; srand(time(NULL)); while(tortoise != End_race && hare != End_race) { MoveT(&tortoise,End_race); MoveHare(&hare,End_race); PrintCurrentPosition(&tortoise,&hare,End_race); timer++; } if(&tortoise>=&hare) cout << "TORTOISE WINS!!! YAY!!!" << endl; else cout << "Hare wins. Yuch." << endl; cout << timer << endl; return 0; } void MoveT(int *tortoisePtr, const int End_race) { int ranNum; ranNum = (rand()%10)+1 ; if(ranNum >= 1 && ranNum <= 5) *tortoisePtr += 3; else if(ranNum == 6 || ranNum == 7) *tortoisePtr -= 6; else *tortoisePtr += 1; if (*tortoisePtr<1) *tortoisePtr=1; else if(*tortoisePtr>End_race) *tortoisePtr=End_race; } void MoveHare(int *harePtr, const int End_race) { int hrandNum; hrandNum= (rand()%10) + 1; if(hrandNum ==3 || hrandNum == 4) *harePtr += 9; else if(*harePtr == 5) *harePtr -= 12; else if(hrandNum >= 6 && hrandNum <= 8) *harePtr += 1; else if(hrandNum > 8) *harePtr -= 2; if(*harePtr < 1) *harePtr = 1; else if(*harePtr > End_race) *harePtr = End_race; cout << endl; } void PrintCurrentPosition(const int *snapperPtr, const int *bunnyPtr, const int End_race) { if(*snapperPtr == *bunnyPtr) cout << setw(*bunnyPtr) << "OUCH!!"; else if(*snapperPtr < *bunnyPtr) { cout << setw(*bunnyPtr) << 'H'; cout << setw(*snapperPtr - *bunnyPtr) << 'T'; } else { cout << setw(*snapperPtr) << 'T'; cout << setw(*bunnyPtr-*snapperPtr) << 'H' << endl; cout << endl; } }
Add this (for now, until you learn why not to).
#include <time>
using namespace std;
void MoveT(int *tortoisePtr, const int End_race); "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
change the headers as
include the following statement after the include statements
OR
append before .
For ex.
Put a before the return statement.
#include <iostream> #include <cstdlib> #include <iomanip> #include <ctime>
include the following statement after the include statements
C++ Syntax (Toggle Plain Text)
using namespace std;
append
C++ Syntax (Toggle Plain Text)
std::
C++ Syntax (Toggle Plain Text)
cout ,endl, setw
For ex.
C++ Syntax (Toggle Plain Text)
std::cout <<
Put a
C++ Syntax (Toggle Plain Text)
std::cin.ignore( );
•
•
Join Date: Sep 2005
Posts: 175
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
Add this (for now, until you learn why not to).
#include <time> using namespace std; void MoveT(int *tortoisePtr, const int End_race);
•
•
•
•
Originally Posted by kahaj
I already have all of that code in there.
Taking your last posted code I get errors. Changing the first few lines to this.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <iomanip> #include <ctime> using namespace std;
C++ Syntax (Toggle Plain Text)
BANG!!! AND THEY'RE OFF !!!! TH TH TH HT HT HT TH HT TH TH TH TH OUCH!! OUCH!! HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HT HTTORTOISE WINS!!! YAY!!! 36
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Help with Classes !!! (Homework) (C++)
- compiling problems (C++)
Other Threads in the C++ Forum
- Previous Thread: Timer event doesn't get triggered
- Next Thread: counts how many times the number 5 appears in array?
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






