My first Project attempt (C++ Need Help)

Started by
22 comments, last by xaviarrob 12 years, 10 months ago
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;
}
Advertisement
why not

int d = 0;
cin >> d;
if(d == 1)
nPriceReduction = true;
else
nPriceReduction = false;

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

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.
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 ?

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

but you should convert the persone input to Upper or Lower Case. (it avoids Case issues)

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.




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.

Stephen M. Webb
Professional Free Software Developer


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.

[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
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.

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!

This topic is closed to new replies.

Advertisement