LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2004, 10:12 PM   #1
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Rep: Reputation: 15
C++ syntax error


C++, syntax errors

I am trying to make a program that computes the area of a given shape, I have eliminated most of the fat finger errors that I made, but can't seam to get rid of these errors. Any help would be greatly appreciated.

The Code
Code:
#include <iostream>



using namespace std;



void circle ( );
void rectangle ( );
void square ( );




int main() 



{

	char choice = ' ';      // Variable declarations

	char doAgain = 'Y';



	do

	{



		cout << "You have the following choices:" << endl;  // making a menu

		cout << "C -- circle" << endl;

		cout << "S -- square" << endl;

		cout << "R -- rectangle" << endl
		cin >> "choice" ;

		choice = toupper(choice);  // makes the case upercase

		switch (choice)

		{

			case 'C': circle( ); break;    // nifty function calls

			case 'S': square( ); break;

			case 'R': rectangle( ); break;



			default: cout << "Invalid choice option.  Please try again." << endl << endl;



		}



		cout << "Would you like to do another arithmetic problem?";

		cin >> doAgain;

		

	}while( toupper(doAgain) == 'Y');



	return 0;
}

void circle ( )
{
	int operand1 ;
	float answer ;
d
	cout << "Enter the radius of the circle. " << endl;

	cin >> operand1;



	answer = (3.141592)*(operand1^2)


	cout << "The area of the circle is " << answer << endl;
}

void square ( )
{
	int operand1 ;
	int operand2 ;
	float answer ;

	cout << "Enter the two sides of the square seperated by a space." << endl;
	cin >> operand1 >> operand2;

	answer = (operand1*operand2)

	cout <<"The area of the square is " << answer << endl;
}

void rectangle ( )
{
	int operand1 ;
	int operand2 ;
	float answer ;

	cout <<"Enter the two side of the rectangle seperated by a space." << endl;
	cin >> operand1 >> operand2;

	answer = (operand1*operand2)

	cout <<"The area of the rectangle is " <<answer <<endl;
}

The errors:
area_calculator.cpp: In function `int main()':
area_calculator.cpp:50: error: syntax error before `>>' token
area_calculator.cpp: In function `void circle()':
area_calculator.cpp:82: error: syntax error before `<<' token
area_calculator.cpp: In function `void square()':
area_calculator.cpp:96: error: syntax error before `<<' token
area_calculator.cpp: In function `void rectangle()':
area_calculator.cpp:110: error: syntax error before `<<' token
 
Old 01-31-2004, 10:18 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
You are missing semi-colons after at least three lines, the answer = line in all three of your functions.

There is also a random d after the variable declarations in the circle function.
 
Old 01-31-2004, 10:20 PM   #3
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You're missing a couple semicolons. all the "answer =" lines and the line before the "cin >> choice". Also remove the quotes around choice.
 
Old 01-31-2004, 10:24 PM   #4
bru
Member
 
Registered: Sep 2003
Location: South Carolina
Distribution: Ubuntu, CentOS, BT4, Debian
Posts: 132

Original Poster
Rep: Reputation: 15
Talking

Thanks jtshaw & crabboy, its always great to have another set of eyes check you stuff!
Thanks again!
 
  


Reply



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
c++ syntax error...HELP!! lmvent Programming 3 09-30-2005 02:40 PM
Syntax error phernand Programming 1 05-10-2005 12:04 PM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:18 PM.

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
Open Source Consulting | Domain Registration