can anyone help?

i'm a beginner and i need to write a simple code for calculating the slices of pizza i can get if a slice is a set area. the code is supposed to do the math automatically once someone puts in the diameter of the pizza but i can't get it going. can anyone help?
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
// This program will tell the user how many slices can be cut from a pizza with 
// a certain diameter. 
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{     
      // Declare variables 
      double  diameter = 0.0;     // Diameter of the pizza
      double  slices = 0.0;       // No. of slices in the pizza
      double  area = 0.0;         // Area of the whole pizza
      const double  oneSlice = 14.125;  // Area of one pizza slice
      double  radius = 0.0;        // half of the diameter  
      const double PI = 3.14159;
      // Display prompt
      cout << "what is the diameter of the pizza?)(inches):" << "\n"; 
      cin >> diameter;
      radius = (diameter / 2.0)
      //  Calculate the area of the pizza
      area = PI * ((diameter / 2.0) * (diameter / 2.0));
      // Calculate number of slices for the size of pizza given
      slices = area / oneSlice;
      // Display results
      cout << "\n\n" << "You have " << slices << " slice(s) in this pizza:" <<  "\n\n"
      system("pause");
      return 0;
}
// end of program
Last edited on
What do you mean by "I can't get it going"? What behaviour do you see? How does that behaviour differ from the behaviour you expect?
well basically it's supposed to calculate the problem and i guess "run" normally but instead it keeps pointing out a problem with the line "area = PI * ((diameter / 2.0) * (diameter / 2.0));" and it will not run until i fix i suppose. i'll be honest im a real beginner so i don't know.
it keeps pointing out a problem

What problem? Is there any particular reason why you're being so vague and evasive, rather than simply giving us all the information that would help us help you?
well no i'm using a free compiler and this is my first semester so the compiler isn't very good it doesn't tell me the problem and i'm not very good at this so i don't know the problem myself i thought maybe someone could just see the problem. i'm sorry like i said i'm afraid i have no idea what the problem is. basically the free compiler highlights the line and puts and "x" near it.
What editor and compiler are you using?
you are missing a ';' on line 19 and again on line 25
yanson thank you so much it worked! and bitrat im using dev-c++ i believe it's called the instructor assigned it to us to use i dont know how good it is as far as compilers go.
Looks like dev-c++ uses the mingw compiler (http://www.mingw.org) which provides messages when I use it in Code::Blocks. I looked at a screenshot for dev-c++:

http://www.bloodshed.net/images/devcpp5_scr.jpg

What do you get in the Compiler or Compiler Log windows at the bottom? Can you change the compiler options anywhere?

Here is an example error message in Code::Blocks:

In function 'int square(int)':
44 error: new declaration 'int square(int)'
17 error: ambiguates old declaration 'float square(int)'
=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===

http://www.codeblocks.org/

Note: Be bold! You can use all the IDE's you can lay your hands on if you want to.
@BitRat @ramirez618
The Bloodshed version of this software is obsolete (last update in 2005), this should not be used.

There is an up to date version called Orwell DevC++ which is ok to use.
Latest version is 5.4.2 - 25 May 2013
http://orwelldevcpp.blogspot.com/

Above code compiled with this gives the messages:
1
2
3
4
5
...\Untitled10.cpp	In function 'int main()':
Line Col  
21    7     ...\Untitled10.cpp	[Error] expected ';' before 'area'
26    7     ...\Untitled10.cpp	[Error] expected ';' before 'system'
15    20    ...\Untitled10.cpp	[Warning] unused variable 'PI' [-Wunused-variable]


That is very specific. It gives the line number and column where the error was found, and states what the problem is.
There are two semicolons missing (at the end of the previous line in each case).

There is also a warning, which is less significant than an error, that the variable PI is not used.

After adding the missing semicolons, that warning goes away.
I had to add this header to get it to compile:
 
#include <cstdlib> 


After that, there is another warning message:
[Warning] variable 'radius' set but not used
This is a useful message, as looking at the code we see line 19
 
    radius = (diameter / 2.0);

but after that radius is never used, which looks like a (small) mistake.
Topic archived. No new replies allowed.