One small problem (very simple fix, but I don't know how) -

#include <iostream>
using namespace std;
void main()
{

double x;
double y;
double z;
char yn;
double tt;
double bs;


cout << "Welcome to xxxxxxx free calculator!" << endl << endl;

cout << "How many adults (age 14 or over) are in your party? " << endl;

cin >> x;

cout << endl;

cout << "How many children (age 5 to 13) are in your party? " << endl;

cin >> y;

cout << endl;

cout << "Do you have a family membership? (y/n) " << endl;

cin >> yn;

cout << endl;

cout << "How many train tickets would you like? " << endl;

cin >> tt;

cout << endl;

cout << "How many bird show tickets would you like? " << endl;

cin >> bs;

cout << endl;

cout << "Your total total fee is: ";

cout << endl;

if (yn == 'y');
{
x * 18 + y * 7.50 + tt * 6 + bs * 5 * .50;
}
cout << x * 18 + y * 7.50 + tt * 6 + bs * 5;











system("pause");

}

// In this program, if the user types "y" for 'if they are a member' it is supposed to give them a 50% discount.

I'm struggling with giving them the discount. I'm so close and I know I'm only one or two steps from finishing, but I can't figure out how to actually give them the discount! Any help would be appreciated.

I think there is something wrong with my if (yn == 'y') thing, I'm not sure what I'm doing wrong.
Simple:
1
2
3
4
5
6
if (yn == 'y');
{
    x * 18 + y * 7.50 + tt * 6 + bs * 5 * .50; // The compiler is told nothing
// About what it has to do with this number.
}
cout << x * 18 + y * 7.50 + tt * 6 + bs * 5;


You should do something like:
1
2
3
4
5
6
float Value = x * 18 + i * 7.50 + tt * 6 + bs * 5;
if(yn == 'y')
{
    Value /= 2;
}
cout << Value;
I've never used float value before.

Essentially float Value takes whatever equation I have (in this case x * 18 + y * 7.50 + tt * 6 + bs * 5;) and it allows me to manipulate it with an 'if' statement?

Thanks for the new information, I've never used that before.
Last edited on
OP wrote:
allows me to manipulate it with an 'if' statement?
Floats are used for storing decimal values just like doubles, but they are 8 Bytes.

Thanks,
Aceix.
Last edited on
Allow Me, Floats are 4 Bytes, Doubles are 8 Bytes.
I Sincerely haven't noticed you was using Doubles, you can change that float to double then. But, as long as you don't need exhaustive floating-point precision, I personally think you should use floats, to let the CPU have the required relax while still producing the (almost) same value.
But, as long as you don't need exhaustive floating-point precision, I personally think you should use floats, to let the CPU have the required relax while still producing the (almost) same value.


My opinion is just the opposite. Unless you need the extra memory, you should prefer doubles over floats.

I haven't run benchmarks, but I would be very surprised if using floats in any way outperformed using doubles (in terms of CPU usage). AFAIK, both floats and doubles get scaled up to whatever register size is in the FPU when calculations are perfomed. If anything... working with doubles is probably faster (for the same reason that working with 'int's is generally faster than working with 'short's).
Topic archived. No new replies allowed.