Skip to main content
GameDev.net gamedev.net
🔒 Locked

circle area and circumference

Started by iammfa Apr 8, 2009 at 4:34 PM 4 replies 1.8k views
Original Post
iammfa
iammfa
hello, this exercise want me ask the user to compute the area and circumference, the compiler get me error, π ≈ 3.14 input radius = 10 this my code: #include using namespace std; int main() { float a, c, r cout << " Enter the radius of a circle:" << endl; cin >> r; a = 3.14 * r * r; c = 2 * 3.14 * r; cout << " The area of a circle " << a << endl; cout << " The circuit of a circle " << c << endl; }
Twisol
Twisol
One, you really need to tell us what error you're getting.

Two, you're missing a semicolon after "float a, c, r".
iammfa
iammfa
this is my output build:

------ Build started: Project: exercise_04, Configuration: Debug Win32 ------
Compiling...
exercise_04.cpp
f:\resources\01_c++\exercises\areacircumference\exercise_04\exercise_04\exercise_04.cpp(7) : error C2146: syntax error : missing ';' before identifier 'cout'
f:\resources\01_c++\exercises\areacircumference\exercise_04\exercise_04\exercise_04.cpp(9) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
f:\resources\01_c++\exercises\areacircumference\exercise_04\exercise_04\exercise_04.cpp(10) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Build log was saved at "file://f:\Resources\01_c++\exercises\AreaCircumference\exercise_04\exercise_04\Debug\BuildLog.htm"
exercise_04 - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Bersicker
Bersicker
float a, c, r; //added a semicolon here


That will solve all your problems.
Chadwell
Chadwell
Quote:
Original post by iammfa
this is my output build:

------ Build started: Project: exercise_04, Configuration: Debug Win32 ------
Compiling...
exercise_04.cpp
f:\resources\01_c++\exercises\areacircumference\exercise_04\exercise_04\exercise_04.cpp(7) : error C2146: syntax error : missing ';' before identifier 'cout'
f:\resources\01_c++\exercises\areacircumference\exercise_04\exercise_04\exercise_04.cpp(9) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
f:\resources\01_c++\exercises\areacircumference\exercise_04\exercise_04\exercise_04.cpp(10) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Build log was saved at "file://f:\Resources\01_c++\exercises\AreaCircumference\exercise_04\exercise_04\Debug\BuildLog.htm"
exercise_04 - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Double click on the line of the first error, it will take you to the line of code that it took place in. Now the error says you are missing a semi-colon, so go to the end of that line and put a semi-colon at the end, like the first answer said.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.