syntax error assistance please

ok first off, im extremely new to C++. taking my first c++ class. i have to write a program, which ive done, but i keep getting the same 5 errors over and over again and i cannot for the life of me figure out why. if anyone could help me it would be greatly appreciated!!

Thanks much all
Justin

program......

// Circle.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
int main ()

{
int R, D; //R is equal to Radius and D is to Diameter
float PI = 3.14159f; //pi is the variable representing Pi
std::cout << "Enter the radius of a circle"; >> // prompts user to input radius
std::cin << "radius"; >> //inputs radius

// calculations are listed below
D = 2*R
C = D*pi
A = R*R*pi

// results display as...
std::cout << "Diameter is"; << diameter << std::endl;
std::cout << "Circumference is"; << fixed << setprecision(4) << circumference << std::endl;
std::cout << "Area is"; << fixed << setprecision(2) << area << std::endl;


errors..

Compiling...
Circle.cpp
c:\documents and settings\misty\my documents\visual studio 2008\projects\circle\circle\circle.cpp(12) : error C2143: syntax error : missing ';' before '>>'
c:\documents and settings\misty\my documents\visual studio 2008\projects\circle\circle\circle.cpp(13) : error C2143: syntax error : missing ';' before '>>'
c:\documents and settings\misty\my documents\visual studio 2008\projects\circle\circle\circle.cpp(21) : error C2143: syntax error : missing ';' before '<<'
c:\documents and settings\misty\my documents\visual studio 2008\projects\circle\circle\circle.cpp(22) : error C2143: syntax error : missing ';' before '<<'
c:\documents and settings\misty\my documents\visual studio 2008\projects\circle\circle\circle.cpp(23) : error C2143: syntax error : missing ';' before '<<'
Build log was saved at "file://c:\Documents and Settings\Misty\My Documents\Visual Studio 2008\Projects\Circle\Circle\Debug\BuildLog.htm"
Circle - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Check your semicolons. You have them placed in the middle of your cout statements. Also your mixing the stream insertion << and extraction >> operators.
ok, i fixed the <<<>> errors. ive got them all flipped to << "text" << . however (and again i appologize for being so new to all this and not knowing), but it seems the semi-colons have to be there in order for them to function right. without them, the program dislikes me, even more than it did to begin with! lol
A semicolon denotes the end of the statement line. So saying:
std::cout << "Diameter is"; << diameter << std::endl;

really means
1
2
std::cout << "Diameter is"; 
<< diameter << std::endl;

with the second line producing an error. Post your code again and let's see what you have now.
your 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
program......

// Circle.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
int main ()

{
int R, D; //R is equal to Radius and D is to Diameter
float PI = 3.14159f; //pi is the variable representing Pi
std::cout << "Enter the radius of a circle"; >> // prompts user to input radius
std::cin << "radius"; >> //inputs radius

// calculations are listed below
D = 2*R
C = D*pi
A = R*R*pi

// results display as...
std::cout << "Diameter is"; << diameter << std::endl;
std::cout << "Circumference is"; << fixed << setprecision(4) << circumference << std::endl;
std::cout << "Area is"; << fixed << setprecision(2) << area << std::endl;

You had too many syntax errors , i just wrote out a corrected version of your code
so review this and compare the syntax of both source codes

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
#include <iostream>
#include <iomanip>
#include <limits> // Only used for keeping window alive

using namespace std; // easier then sprinkling std::'s everywhere
int main()
{
double C,R,D,A; // You want doubles for these operations, not ints
const double PI = 3.14159;
cout<<"Enter Radius of Cicle"<<endl
       <<"Radius :";
cin>>R;
//Operations
D = R*2;
C = D*PI;
A = (R*R)*PI;
//Prompt
cout<<"Diameter is "<<D<<endl;
cout<<"Circumference is "<<fixed<<setprecision(4)<<C<<endl;
cout<<"Area is "<<fixed<<setprecision(2)<<A<<endl;

// Keeps Window Open
cout<<"Press Enter to Quit ...";
cin.sync();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
return 0;
}
Last edited on
Topic archived. No new replies allowed.