Need help

This is the first part to my code and I was wondering what is wrong with my if statements.

#include <iostream>
#include <iomanip>

using namespace std;

const static double discountTenPounds = 0.9;
const static double discountTwentyPounds = 0.85;
const static int ouncesPerPound = 16;
double pricePerDay;
int numberOfPounds;

double price = (pricePerDay * numberOfPounds) / (ouncesPerPound * numberOfPounds);

if (numberOfPounds == 1)
{
return price;
}

else if (numberOfPounds == 10)
{
return double price * discountTenPounds
}
else
{
return price * discountTwentyPounds
{

int main()
{
const static int buyOption1 = 1;
const static int buyOption2 = 10;
const static int buyOption3 = 20;

cout >> "Enter price per lb: "
cin << price








return 0;
}

returns take a ; on the end like most other statements. So does cin. The compiler should be telling you about missing ;s but sometimes the errors can get weird once it gets confused.
return price * discountTwentyPounds ; //like this

also you may want to offer the discounts based off < rather than ==
eg
if( nop > 20)
//give 20 pound discount
else
if nop > 10
//give 10 pound discount, but not if its above 20, due to the else!
else if nop > 1
..etc
Last edited on
akeilo;
@jonnin is correct, you need a semicolon after pretty much anything in C++, except preprocessor directives like #include , #pragma , #define , etc.

In addition, on line 26, you had an open bracket instead of a closing bracket, that was probably part of it.
1
2
3
4
5
6
7
else
{
    return price * discountTwentyPounds
{ // this was affecting your main function right after it.

int main ()
{


And, you used the wrong operands for cin and cout. Think of it as << is the stuff going to cout (common output) and >> is the stuff going to cin (common input).
1
2
3
4
5
6
// NOT this:
std::cout >> "Enter price per lb: " << std::endl;
std::cin << price;
// YES this:
std::cout << "Enter price per lb: " << std::endl;
std::cin >> price;


Why are you using global variables, anyway? I can understand with the const variables for discounts, but the pricePerDay and the numberOfPounds would probably be better in the main.

Also, those if statements just will not work where they are. You'd be better off putting them inside a function, either main or something listed after main, along with your arithmetic operation on line 12. This looks like an unfinished program though, so maybe you were already planning to do that.
Last edited on
Topic archived. No new replies allowed.