LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-23-2012, 10:08 AM   #1
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Rep: Reputation: Disabled
Can some one explain how to fix my errors for my example??


Code:
#include <iostream>
using namespace std;
bool zero (int, int, int, int, int);
int a ( int, int);
int b ( int, int);
int c (int, int);
int d ( int, int);
int main ()
{
    int P, X, Q, R, Y, A, B, C, D;
    bool zero
    cout <<"Enter Five Integers:";
    cin >>X >>Y >>P >>Q >>R;
    zero = zero ( X, Y, P, Q, R);
{
    if ( zero == true)
    A = int a (X, Y)
    B = int b (A, P)
    C = int c (B, Q)
    D = int d (C, R)
    cout <<"Out of Order:" << P << X << Q << R << Y << endl
    <<"Sum: A= " << A << endl
    <<"Product: B= " << B << endl
    <<"Difference: C= " << C << endl
    <<"Division: D= " << D << endl;
    else
    cout << "At least one of your inputs is incorrect. Try again.
}
    ;return 0;
}

int a (int X, int Y)
{
    A = X + Y;
    return A;
}
int b (int A, int P)
{
    B = A * P;
    return B;
}
int c (int B, int Q)
{
    C = B - Q;
    return C;
}
int d ( int C, int R)
{
    D = C / R;
    return D;
}
bool zero ( int X, int Y, int P, int Q, int R )
{
    if ( X > 0, && Y > 0, && P > 0, && Q > 0, && R > 0 )
    return true;
    else
    return false:
}
here are the errors
Code:
Lab5.cpp:34: error: missing terminating " character
Lab5.cpp: In function ‚int main()‚
Lab5.cpp:19: error: expected initializer before ‚cout‚
Lab5.cpp:21: error: assignment of function ‚bool zero(int, int, int, int, int)‚
Lab5.cpp:21: error: cannot convert ‚bool‚ to ‚bool ()(int, int, int, int, int)‚ in assignment
Lab5.cpp:23: error: ISO C++ forbids comparison between pointer and integer
Lab5.cpp:24: error: expected primary-expression before ‚int‚
Lab5.cpp:24: error: expected `;' before ‚int‚
Lab5.cpp:35: error: expected primary-expression before ‚}‚ token
Lab5.cpp:35: error: expected `;' before ‚}‚ token
Lab5.cpp: In function ‚int a(int, int)‚:
Lab5.cpp:41: error: ‚A‚ was not declared in this scope
Lab5.cpp: In function ‚int b(int, int)‚:
Lab5.cpp:46: error: ‚B‚ was not declared in this scope
Lab5.cpp: In function ‚int c(int, int)‚:
Lab5.cpp:51: error: ‚C‚ was not declared in this scope
Lab5.cpp: In function ‚int d(int, int)‚:
Lab5.cpp:56: error: ‚D‚ was not declared in this scope
Lab5.cpp: In function ‚bool zero(int, int, int, int, int)‚:
Lab5.cpp:64: error: expected ‚;‚ before ‚:‚ token
Lab5.cpp:64: error: expected primary-expression before ‚:‚ token
Lab5.cpp:64: error: expected `;' before ‚:‚ token
Lab5.cpp:61: error: label ‚Y‚ used but not defined
Lab5.cpp:61: error: label ‚P‚ used but not defined
Lab5.cpp:61: error: label ‚Q‚ used but not defined
Lab5.cpp:61: error: label ‚R‚ used but not defined
 
Old 09-23-2012, 01:05 PM   #2
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
Line 10: append a ;
Line 11: rename the variable "zero" to something else, it conflicts with the function "zero()"
Line 14 and 16: update the name "zero" to whatever you changed it to
Line 16: append a {
Append a ; to each line from 17-20
Remove int from each line from 17-20
Line 25: append a }
Line 27: append ";
Remove all commas from line 54
Line 57: replace the : with a ;

In functions a, b, c and d: the variables A, B, C, and D respectively are out of scope, either make them global or pass them as arguments.

Hope this helps.
 
1 members found this post helpful.
Old 09-23-2012, 01:14 PM   #3
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
what do you mean out of scope
 
Old 09-23-2012, 01:18 PM   #4
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
They cannot be accessed by the functions because, as far as the function is concerned, they don't exist. Variable created inside of main() can only be accessed inside of main().
 
1 members found this post helpful.
Old 09-23-2012, 01:22 PM   #5
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
so remove them from the main function?
 
Old 09-23-2012, 01:26 PM   #6
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
You could create them at the top of the file (globally) or you could not use them in the other functions. Here is an example (with some other changes) that doesn't need them in the other functions:
Code:
#include <iostream>
using namespace std;
bool zero (int, int, int, int, int);
int a ( int, int);
int b ( int, int);
int c (int, int);
int d ( int, int);
int main ()
{
	int P, X, Q, R, Y;
	cout << "Enter Five Integers:";
	cin >> X >> Y >> P >> Q >> R;
	if ( zero ( X, Y, P, Q, R)) // This is the same as if(zero(X,Y,P,Q,R) != false)
	{
		int A, B, C, D; // Variables should be as local as possible
		A = a (X, Y);
		B = b (A, P);
		C = c (B, Q);
		D = d (C, R);
		cout << "Out of Order:" << P << X << Q << R << Y << endl
			<< "Sum: A= " << A << endl
			<< "Product: B= " << B << endl
			<< "Difference: C= " << C << endl
			<< "Division: D= " << D << endl;
	}
	else
		cout << "At least one of your inputs is incorrect. Try again.";
	return 0;
}

int a (int X, int Y)
{
	return X + Y; // You can just return the value without saving it
}
int b (int A, int P)
{
	return A * P;
}
int c (int B, int Q)
{
	return B - Q;
}
int d ( int C, int R)
{
	return C / R;
}
bool zero ( int X, int Y, int P, int Q, int R )
{
	return X && Y && P && Q && R; // Returns 0 if any of the variables are 0, else 1
}

Last edited by byannoni; 09-23-2012 at 01:27 PM.
 
1 members found this post helpful.
Old 09-23-2012, 01:37 PM   #7
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
so this is what I get now

Lab5.cpp: In function ‚int main()‚:
Lab5.cpp:32: error: expected primary-expression before ‚else‚
Lab5.cpp:32: error: expected `;' before ‚else‚
 
Old 09-23-2012, 01:39 PM   #8
carlosk711
Member
 
Registered: Sep 2012
Posts: 52

Original Poster
Rep: Reputation: Disabled
fixed it myself, thank you!
 
Old 09-23-2012, 01:40 PM   #9
byannoni
Member
 
Registered: Aug 2012
Location: /home/byannoni
Distribution: Arch
Posts: 128

Rep: Reputation: 36
You're welcome!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Several Errors when using ssh -X. Can't find fix. crosside8 Linux - Server 2 11-15-2011 10:22 AM
while compiling kernel i get errors,how do i fix them? rixtr66 Slackware 4 08-23-2008 11:26 AM
Please help, what do these errors mean and how to fix them? lexington Linux - Newbie 3 05-08-2004 12:41 PM
Few errors i would like to fix nivek7 Slackware 3 04-17-2004 01:33 AM
gcc errors: What are they and how to fix sleepwalker1.0 Programming 8 01-06-2003 02:57 PM


All times are GMT -5. The time now is 09:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration