Jump to content
  • Advertisement
Sign in to follow this  
xaviarrob

My first Project attempt (C++ Need Help)

This topic is 2587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So hi!

I'm new to the foum (registering anyway) and I need some help. I know this doesn't pertain strait to game programming but it is a programming problem.

I'm creating a calculator that calculates how much it costs when districts or schools increase their levies.
The problem is indicated where nPriceReduction starts.



//The purpose of this program is to show my community (and any if that) how inexpensive levy increases are.
//This will eventually become a windowed program.
#include <iostream>
#include <conio.h>

using namespace std;

int main(){
cout << "Please enter your house's market value" << endl;
int nY; // Market value of house
cin >> nY;
cout << "Please enter the number of mills" << endl;// For those unfamiler with mills, 1 mill = 1% increase.
int nZ;
cin >> nZ;
int nNumberOfMills = nZ;
int nTaxPercent = .35;
float nX = nY * nTaxPercent;//Takes the market value of house and multiplies it by the percent of the house you pay taxes on.
float nMill = .001;// 1% = 1 mill
float nMillCalc = nZ * nMill;//Multiplies the value of a mill by how many there are.
cout << "Are you getting a goverment price reduction?(true/false)" << endl;
//Having trouble with this section, I essentially want the user to type yes/no and for it to do the correct if statement apropriatly.
//When I execute this it always assumes the answer is false.
bool nPriceReduction;
cin >> nPriceReduction;
if (bool nPriceReduction = true){
cout << "Your proporty taxes cost for " << nZ << " mill(s) is {:content:}quot; << nMillCalc * nX * .875 << " per year or {:content:}quot; << ((nMillCalc * nX * .875) / 12) << " per month " << endl;

}else if (char nPriceReduction = false){
cout << "Your proporty taxes cost for " << nZ << " mill(s) is {:content:}quot; << nMillCalc * nX << " per year or {:content:}quot; << ((nMillCalc * nX) / 12) << " per month " << endl;}
getch();
return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
I would like the user to be able to enter the word yes so they don't get confused with it, on a side note if anyone could point me towords making this in a window with GUI that would be great.

Share this post


Link to post
Share on other sites
what about (have not tested this so there could be errors)


cout << "Are you getting a goverment price reduction?(Yes / No)";
string d;
cin >> d;
if(d == 'string("yes")')
nPriceReduction = true;
else
nPriceReduction = false;

or more simply

cout << "Are you getting a goverment price reduction?(Y / N)";
char d = 'n';
cin >> d;
if(d == 'y')
nPriceReduction = true;
else
nPriceReduction = false;


that better ?

Share this post


Link to post
Share on other sites



bool nPriceReduction;
cin >> nPriceReduction;
if (bool nPriceReduction = true){
cout << "Your proporty taxes cost for " << nZ << " mill(s) is {:content:}quot; << nMillCalc * nX * .875 << " per year or {:content:}quot; << ((nMillCalc * nX * .875) / 12) << " per month " << endl;

}

Perhaps what you meant was this?

bool nPriceReduction;
cin >> nPriceReduction;
if (nPriceReduction){
// ...
}

What you have declares a temporary variable and assigns it the value true, all inside the expression of your if-statement.

Share this post


Link to post
Share on other sites

what about (have not tested this so there could be errors)


cout << "Are you getting a goverment price reduction?(Yes / No)";
string d;
cin >> d;
if(d == 'string("yes")')
nPriceReduction = true;
else
nPriceReduction = false;

or more simply

cout << "Are you getting a goverment price reduction?(Y / N)";
char d = 'n';
cin >> d;
if(d == 'y')
nPriceReduction = true;
else
nPriceReduction = false;


that better ?


When compiling this since there is nothing terminating that else everything beyond the tags evaluates to 0.

Share this post


Link to post
Share on other sites

[quote name='xaviarrob' timestamp='1306351294' post='4815727']

bool nPriceReduction;
cin >> nPriceReduction;
if (bool nPriceReduction = true){
cout << "Your proporty taxes cost for " << nZ << " mill(s) is {:content:}quot; << nMillCalc * nX * .875 << " per year or {:content:}quot; << ((nMillCalc * nX * .875) / 12) << " per month " << endl;

}

Perhaps what you meant was this?

bool nPriceReduction;
cin >> nPriceReduction;
if (nPriceReduction){
// ...
}

What you have declares a temporary variable and assigns it the value true, all inside the expression of your if-statement.

[/quote]
I dont quite understand what you mean here

Share this post


Link to post
Share on other sites
if (bool nPriceReduction = true)

1) You do not need to specify the data type in an if statement; nPriceReduction is already a bool data type.
2) Since nPriceReduction is already a bool data type you can simply say "if (nPriceReduction) {}"
3) Always use the "equal to" (==) when doing a comparing value(s) and not the assignment operator (=)


For instance:
if (nPriceReduction = true) will always assign true to nPriceReduction and will always evaluate as true
if (nPriceReduction == true) will always compare nPriceReduction to see if it is true or false (== is equal to; != is not equal to)

That is what the other members were talking about.

Share this post


Link to post
Share on other sites

if (bool nPriceReduction = true)

1) You do not need to specify the data type in an if statement; nPriceReduction is already a bool data type.
2) Since nPriceReduction is already a bool data type you can simply say "if (nPriceReduction) {}"
3) Always use the "equal to" (==) when doing a comparing value(s) and not the assignment operator (=)


For instance:
if (nPriceReduction = true) will always assign true to nPriceReduction and will always evaluate as true
if (nPriceReduction == true) will always compare nPriceReduction to see if it is true or false (== is equal to; != is not equal to)

That is what the other members were talking about.



Thanks a bunch this is exactly the answer I wanted. If anyone could point me in the direction of translating all of this out of console and into a window I would much appriciate it!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!