Hey guys i am working on a program that does many simple things to show my teacher that i have learned to use functions. i have repeatedly read this forum and checked many other ones but none of them seem to solve my problem. as the code below is linking ( i think ), I get these messages in the error list:
error LNK1120: 1 unresolved externals
error LNK2001: unresolved external symbol_mainCRTStartup
Can someone please help me solve this!
Here is my code
#include <iostream.h>
#include <math.h>
using namespace std;
int a;
int b;
float c;
int d;
float p_theorem (int side_a, int side_b){
return sqrtf((side_a * side_a)+(side_b * side_b));
}
float p_theorem_reverse (int side_c, int side_d){
return sqrtf((side_c * side_c)-(side_d * side_d));
}
void game(int x){
if (x < 5){
cout<<"Your number is too low"<<endl<<"Please guess again: ";
cin>>x;
}
else 开发者_开发知识库if (x > 5){
cout<<"Your number is too big"<<endl<<"Please guess again: ";
cin>>x
}
else (x == 5){
cout<<"Good job, You guessed the number!"<<endl;
system("PAUSE");
}
}
void stuff(){
cout<<"Developed by Ely Eastman"<<endl<<"Computer 35, T.H. Rogers Secondary School, Houston, TX"<<endl;
system("PAUSE");
}
int main(void)
{
cout<<"Welcome to the Multi-Function Program"<<endl
<<"Enter 1 for finding the hypotenuse of a right triangle"<<endl
<<"Enter 2 for finding the leg of a right triangle"<<endl
<<"Enter 3 for the Guessing Game Beta"<<endl
<<"Enter 4 for Developer Information"<<endl;
cin>>d
if (d == 1){
cout<<"Welcome to the Pythagorean Theorem Solver"<<endl
<<"Please enter the length of one leg of the triangle: ";
cin>>a;
cout<<"Please enter the length of the other leg of the triangle: ";
cin>>b;
c = p_theorem(a, b);
cout<<"The length of the hypotenuse is "<<c<<endl;
system("PAUSE");
}
else if (d == 2){
cout<<"Welcome to the Reverse Pythagorean Theorem"<<endl
<<"Please enter the length of the Hypotenuse: ";
cin>>a;
cout<<"Please enter the length of the known leg: ";
cin>>b;
c = p_theorem_reverse(a, b);
cout<<"The length of the leg is: "<<g<<endl;
system("PAUSE")
}
else if (d == 3){
cout<<"Welcome to the Guessing Game Beta"<<endl
<<"Please guess a number 1-10: ";
cin<<a
game(a);
}
else if (d == 4){
stuff();
}
return 0;
}
You have dozens of missing ";" and a missing if statement. Also the length of the game "g" is undefined. And your cin ">>" operators are reversed in some cases ...
Edit: As Neil pointed out in the comments, you probably need to specify that you are creating a console application.
Working? Code (Please try to notice what I changed and not just copy/paste it, some of the mistakes are pretty basic knowledge):
#include <iostream>
#include <math.h>
using namespace std;
int a;
int b;
float c;
int d;
float p_theorem (int side_a, int side_b){
return sqrtf((side_a * side_a)+(side_b * side_b));
}
float p_theorem_reverse (int side_c, int side_d){
return sqrtf((side_c * side_c)-(side_d * side_d));
}
void game(int x)
{
if (x < 5)
{
cout<<"Your number is too low"<<endl<<"Please guess again: ";
cin>>x;
}
else if (x > 5){
cout<<"Your number is too big"<<endl<<"Please guess again: ";
cin>>x;
}
else if (x == 5)
{
cout<<"Good job, You guessed the number!"<<endl;
system("PAUSE");
}
}
void stuff(){
cout<<"Developed by Ely Eastman"<<endl<<"Computer 35, T.H. Rogers Secondary School, Houston, TX"<<endl;
system("PAUSE");
}
int main(void)
{
cout<<"Welcome to the Multi-Function Program"<<endl
<<"Enter 1 for finding the hypotenuse of a right triangle"<<endl
<<"Enter 2 for finding the leg of a right triangle"<<endl
<<"Enter 3 for the Guessing Game Beta"<<endl
<<"Enter 4 for Developer Information"<<endl;
cin>>d;
if (d == 1){
cout<<"Welcome to the Pythagorean Theorem Solver"<<endl
<<"Please enter the length of one leg of the triangle: ";
cin>>a;
cout<<"Please enter the length of the other leg of the triangle: ";
cin>>b;
c = p_theorem(a, b);
cout<<"The length of the hypotenuse is "<<c<<endl;
system("PAUSE");
}
else if (d == 2){
cout<<"Welcome to the Reverse Pythagorean Theorem"<<endl
<<"Please enter the length of the Hypotenuse: ";
cin>>a;
cout<<"Please enter the length of the known leg: ";
cin>>b;
c = p_theorem_reverse(a, b);
cout<<"The length of the leg is: "<<c<<endl; // <- What is g?!!! I think you had a typo
system("PAUSE");
}
else if (d == 3){
cout<<"Welcome to the Guessing Game Beta"<<endl
<<"Please guess a number 1-10: ";
cin>>a;
game(a);
}
else if (d == 4){
stuff();
}
return 0;
}
Assuming you are on Visual Studio 2005, go to the Properties of the project, open Linker in Configuration Properties
Subsystem will be the first item on the list. Then select Windows (/SUBSYSTEM:WINDOWS)
Check your project settings and see if the /NODEFAULTLIB
linker option is set. If it is, unset it.
精彩评论