ok i started over and ran into a fatal error

hey there im starting my program over so im trying to just bulid the first option then add the rest of the ptions once i have this working but im getting a fatal error... everything looks good to me but i suck at it lol

finalproject2.obj : error LNK2019: unresolved external symbol "int __cdecl hw1(void)" (?hw1@@YAHXZ) referenced in function _main
1>C:\Users\Rachael Ann\Documents\Visual Studio 2010\Projects\finalproject\Debug\finalproject.exe : fatal error LNK1120: 1 unresolved externals

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  #include <iostream>
#include <string>

using namespace std;


int hw1(); 
void hw2(string word);
void hw3(string word);
void hw4(string word);
void hw5(string word);
void hw6(string word); 
void hw7(string word);
void closed(string word);

int number1; 
 int number2; 
 int number3; 
 int smallest;
 int largest; 
 int sum;

double average; 
 int product;
 


int main() 
{
		int choice; 
	
	
	cout	 << " Welcome to my final C++ program \n " 
			 << " Please choose from the following selections \n\n"

			 << " 1: Homework 1.\n "
    		 <<" 2: Homework 2.\n "
    		 <<" 3: Homework 3.\n "
			 <<" 4: Homework 4.\n "
    		 <<" 5: Homework 5.\n "
			 <<" 6: Homework 6.\n "
			 <<" 7: Homework 7.\n "
			 <<" 8: Exit.\n\n " ;
	
					cin >> choice;  
		

					
		switch (choice)
	{
	
		case 1:
        cout << "you have selected \n";
        hw1() ; 
        break;
		


     default: cout << "Your selection must be between 1-8 \n"

;
	int hw1();
	

 
 cout << "Input three different Numbers: "; 
 cin >> number1 >> number2 >> number3;
 largest = number1; 

 if (number2 >= largest)
largest = number2;
 
 if (number3 >= largest) 
largest = number3; smallest = number1;

 if (number2 < smallest)
	smallest = number2;

 if (number3 < smallest)
	 smallest = number3;
 
 cout << "The answers are...\n" 

			 << "Largest Value:" << largest << std::endl

			 << "Smallest Value:" << smallest << std::endl

  			 << "Sum: " << (sum = (number1 + number2 + number3)) << std::endl

			 << "Average: " << (average = (number1+number2+number3)/3.0f) << std::endl

			 << "Product: " << (product = (number1*number2*number3)) << std::endl;

 system("pause");
 return 0;

		
		}
}
Did you define int hw1() someplace? You call it a couple times, but there is nothing in your code, that I can see, that goes beyond that.

<edit>
Is line 62 supposed to start the definition, and what follows the body of the function? If so, you need to move it outside of main() and surround the body with curly brackets instead of ending it with a semicolon.
Last edited on
ok so i did that but now it will compile and i can not get it to advance to hw1 .... it stays there. also how do i get it to return to the main menu when i am done

and i dont understand why

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <string>

using namespace std;


void hw1(); 
void hw2(string word);
void hw3(string word);
void hw4(string word);
void hw5(string word);
void hw6(string word); 
void hw7(string word);
void closed(string word);

int number1; 
 int number2; 
 int number3; 
 int smallest;
 int largest; 
 int sum;

double average; 
 int product;
 


int main() 
{
		int choice; 
	
	
	cout	 << " Welcome to my final C++ program \n " 
			 << " Please choose from the following selections \n\n"

			 << " 1: Homework 1.\n "
    		 <<" 2: Homework 2.\n "
    		 <<" 3: Homework 3.\n "
			 <<" 4: Homework 4.\n "
    		 <<" 5: Homework 5.\n "
			 <<" 6: Homework 6.\n "
			 <<" 7: Homework 7.\n "
			 <<" 8: Exit.\n\n " ;
	
					cin >> choice;  
		

					
		switch (choice)
	{
	
		case 1:
        cout << "you have selected \n";
        hw1() ; 
        break;
		


     default: cout << "Your selection must be between 1-8 \n"

		;}
}
	 void hw1()
	
	 {
 cout << "Input three different Numbers: "; 
 cin >> number1 >> number2 >> number3;
 largest = number1; 

 if (number2 >= largest)
largest = number2;
 
 if (number3 >= largest) 
largest = number3; smallest = number1;

 if (number2 < smallest)
	smallest = number2;

 if (number3 < smallest)
	 smallest = number3;
 
 cout << "The answers are...\n" 

			 << "Largest Value:" << largest << std::endl

			 << "Smallest Value:" << smallest << std::endl

  			 << "Sum: " << (sum = (number1 + number2 + number3)) << std::endl

			 << "Average: " << (average = (number1+number2+number3)/3.0f) << std::endl

			 << "Product: " << (product = (number1*number2*number3)) << std::endl;

 system("pause");
 return ;
	}
Last edited on
Your indentation is really bad which is why you aren't seeing what's wrong.

first thing, line 63:

void hw1(); // <-- don't put a semi-colon there if this is your function implementaion start

then:
- lines 94 and 95 have no semi-colons at the end of the lines and they need them.
- line 97, why the 2 closing brace??
- you are returning a value from your function, but you've declared it void i.e. not to return anything from that function.
Last edited on
ok i fixed most of it on the second post im changing the void to int now
{ok i fixed it to a int but from what i can see it i getting hung up on the switch}
Last edited on
bump/\/\/\/\/\/\
If you want to go back to the menu, you need to put it all in a loop. Otherwise it will take a selection, execute it, and continue on toward the end of the program.
ok but right now i cant get it to go in a program.. it compiles the menu comes up and i enter one and it doesnt do anything
As mutexe pointed out, you formatting is really bad making it hard to see what is happening.

It works for me and goes through hw1() fine, I did not verify if the answers were right though or that everything printed correctly. However, I am pretty sure that you do not want lines 94 and 95 at the end of the hw1().
Topic archived. No new replies allowed.