Syntax Errors, please help!

It would be greatly appreciated if you guys help me fix these syntax errors. Just in case you have any questions regrading the application its suppose to collect numbers and end with a press of the enter key. Once that happens, its suppose to show the mean, median, and mode (I have not added those yet, fyi).


C++ Code:
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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void Nums(vector<int>&values)
{
	int i= -1;
	string temp;

	do
	{
		i++;
		values.resize(i+1);
		cout << "Please enter a number <ENTER to quit>:   ";
		getline(cin, temp);
		values[i] = atoi (temp.c_str());
	} while (temp != "");
}

void ShowNums(vector <int> values)
{
	
//Need to add a mean, median, & mode

}

void Swap (int & first, int & second)
{
	string temp = first;
	first = second;
	second =  temp;
}

void SortNums (vector<int>values)
{

	for (int i=0; i<values.size(); i++)
      for (int j=0; j<values.size(); j++)
		  if (values[j]) < (values[j+1])
		  Swap(values[j], values[j+1]);
}

void main()
{
	vector <int> values;

	GetNums(values);
	cout << endl;

	SortNums(values); 
	cout << endl;

	ShowNums(values);
	cout << endl;
}



Syntax Errors:
1
2
3
4
5
6
7
8
9
10
11
Compiling...
Project.001.cpp
c:\documents and settings\two\desktop\project.001.cpp(31) : error C2440: 'initializing' : cannot convert from 'int' to 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
        No constructor could take the source type, or constructor overload resolution was ambiguous
c:\documents and settings\two\desktop\project.001.cpp(33) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is
 no acceptable conversion)
c:\documents and settings\two\desktop\project.001.cpp(41) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\two\desktop\project.001.cpp(49) : error C2065: 'GetNums' : undeclared identifier
Error executing cl.exe.

Project.001.obj - 4 error(s), 0 warning(s)


Last edited on
line 31: first is of type int, and you are trying to store it into a string.
Change to int temp = first;

line 41 if (values[j]) < (values[j+1]) is a typo.
It should be if (values[j] < values[j+1])

line 42: there is no function called GetNums. Maybe you meant Nums?
Last edited on
That worked beautifully.

Thank you very much!
Topic archived. No new replies allowed.