Well I am fairly new to C++ and am supposed to create a program that compares various pizza's between size and price so the unit would be dollar/area^2

The input from the user should first be how many items you have to compare..
The next input from the user should be the price of the pizza and the diameter of the pizza in inches.
So I have got that down.... But I don't know how I would save each input (inches and price) so that they are saved in seperate variables and could calculate the final value of the pizza (dollar/area^2) and how to compare them.... This program so far compiles and runs...
This is what I have so far

#include <stdio.h>
int main ()
int items;
float inches;
int i = 0;
float price;
float area;
float final;

printf("The number of pizza options you have?\n");
scanf("%d", &items);
while(i++, i<=items){
printf("How big is the pizza diameter in inches?\n");
scanf("%f", &inches);
printf("How much does the pizza cost?\n");
scanf("%f", &price);


Could someone help me out and point me at the right direction ?

First, the code you posted uses pure C syntax so it may be better posted on the C board. However, the logic will be the same whether it's C or C++, only the syntax will differ.

Since the area of a circle is the product of pi times the square of the radius you can neglect the pi part and just use the radius squared part in the calculation of the relative cost. The radius is the diameter divided by 2 and to square it you can either use the pow() function or mulitply the radius by itself.

If all you want to know is the cheapest or the most expensive, then you can just keep track of the appropriate values on and ongoing basis during the input loop.

input cost
input diameter
calculate radius
calculate radius squared
calculate cost per unit
compare cost to current cheapest or most expensive and update the cheapest or most expensive as need be.

If you want to keep track of all the input numbers and you don't know ahead of time how many inputs there will be, you're going to need you can't hard code them so you have to use a container that can be sized/resized at run time. The prototypical container would likely be a list, though if you're willing to use dynamic memory to write the list you could do it with an array using dynamic memory as well.

This article has been dead for over six months. Start a new discussion instead.