help with n00b code

Hey i'm a n00b to C++. just got visual studios express editinon 2008 and im using it as a compiler. I write my code in notepad. I'm having trouble with this program: it's supposto ask for 5 values and convert them to their absolute values.
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
//program to average absolute values
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{

//a,b,c,d,e variables obtain user input below, these will be changes to 
//their absolute values

	int a,b,c,d,e,f,g,h,i,j;

	cout << "Input 5 numbers please. \n";
		cin << a;
	cout << "\n1... \n";
		cin << b;
	cout << "\n2... \n";
		cin << c;
	cout << "\n3... \n";
		cin << d;
	cout << "\n4... \n";
		cin << e;
	cout << "\n5... \n";

//f,g,h,i,j are defined to retain the original values of a,b,c,d,e
//they will remain the user inputed values

	a=f;
	b=g;
	c=h;
	d=i;
	e=j;

//x,y,z,p,q are made to recive the absolute values of a,b,c,d,e

	int x,y,z,p,q;

	abs(a)=x;
	abs(b)=y;
	abs(c)=z;
	abs(d)=p;
	abs(e)=q;

	cout << "\nThe absolute value of " << f << " is " << x << ".";
	cout << "\nThe absolute value of " << g << " is " << y << ".";
	cout << "\nThe absolute value of " << h << " is " << z << ".";
	cout << "\nThe absolute value of " << i << " is " << p << ".";
	cout << "\nThe absolute value of " << j << " is " << q << ".";

	cout << "\n";

	int average;
	
	average=(x+y+z+p+q)/5;

	cout << "The average of your values is: " << avreage << ".";

	return 0;
}


also, is this possible?
...
int a,b
cout <<"Input a number:\n";
cin >> a,b
...
?
thanks for the help,
enduser000
Last edited on
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
abs(a) = x; // wrong
x = abs(a); 

...
     double average; //doulble would be better for an average
	
     average= (x+y+z+p+q) / 5.0;  // 5.0 will make it do a floating point division
Thnaks, that will prevent me from making future errors. I am still getting over 100 errors when I try to compile. Here is the new 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
58
59
60
//program to average absolute values
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{

//a,b,c,d,e variables obtain user input below, these will be changes to 
//their absolute values

	int a,b,c,d,e,f,g,h,i,j;

	cout << "Input 5 numbers please. \n";
		cin << a;
	cout << "\n1... \n";
		cin << b;
	cout << "\n2... \n";
		cin << c;
	cout << "\n3... \n";
		cin << d;
	cout << "\n4... \n";
		cin << e;
	cout << "\n5... \n";

//f,g,h,i,j are defined to retain the original values of a,b,c,d,e
//they will remain the user inputed values

	a=f;
	b=g;
	c=h;
	d=i;
	e=j;

//x,y,z,p,q are made to recive the absolute values of a,b,c,d,e

	int x,y,z,p,q;

	x=abs(a);
	y=abs(b);
	z=abs(c);
	p=abs(d);
	q=abs(e);

	cout << "\nThe absolute value of " << f << " is " << x << ".";
	cout << "\nThe absolute value of " << g << " is " << y << ".";
	cout << "\nThe absolute value of " << h << " is " << z << ".";
	cout << "\nThe absolute value of " << i << " is " << p << ".";
	cout << "\nThe absolute value of " << j << " is " << q << ".";

	cout << "\n";

	double average;
	
	average=(x+y+z+p+q)/5.0;

	cout << "The average of your values is: " << avreage << ".";

	return 0;
}

The errors will not all fit but i'll place a few as most of them are the same.

Errors:
absolute.cpp
absolute.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\ostream(930) : see declaration of 'std::operator <<'
absolute.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\ostream(930) : see declaration of 'std::operator <<'
absolute.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\ostream(930) : see declaration of 'std::operator <<'

absolute.cpp(15) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\ostream(923) : see declaration of 'std::operator <<'

absolute.cpp(17) : error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'std::istream'
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\ostream(909) : see declaration of 'std::operator <<'


Again thanks for taking a look,
enduser000



1
2
cin << a; //incorrect
cin >> a; //correct 


That is probably the source of most of the other errors.

I also noticed that the last "average" in the line "The average of your values..." is spelled incorrectly.
Last edited on
closed account (z05DSL3A)
I am only giving the code a quick scan, but
1
2
 cin << a; //wrong operator
 cin >> a;


The thing is one error will often cause a cascade of errors, so always start at the first one, the others may not be errors. change all your 'cin <<' to 'cin >>'

Last edited on
alright thanks (that's why this is "n00b code" xD) i am just getting one error with this section now.

1
2
3
double average;
	
	average=(x+y+z+p+q)/5.0;


Error:
absolute.cpp
absolute.cpp(57) : error C2065: 'avreage' : undeclared identifier
closed account (z05DSL3A)
That is a simple miss spelling on the following line
 
   cout << "The average of your values is: " << avreage << ".";

try
 
   cout << "The average of your values is: " << average<< ".";
wow, n00b mistake again. thanks a bunch for your help everyone.

w00t C++

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main()
{
     cout << "Hello World";

return 0;
}

Topic archived. No new replies allowed.