# Thread: Calculations are stopping my program from executing? Beginner question

1. ## Calculations are stopping my program from executing? Beginner question

Hey guys, first post so first I'd like to say hello. I've followed the site and read multiple tutorials for C++ so far. I'm actually going to school for programming. Although I'm quite the beginner, I'm very eager to learn.

I have this issue with some very basic code that I figured maybe someone could point me in the right direction to a solution. Basically if I leave the calculations out, I can get the outputs displayed, but once I add them in, only the input works. Anyways, onto the code.

Code:
```#include <iostream>
#include <string>

using namespace std;

//declaring global variables

double totalPrice = 0;
double purchasePrice = 0;
double totalTax = 0;
float countyTax = 0;
float stateTax = 0;

//prototpyes
void input();
void calc();
void output();

int main()
{
//calls in main
input();
calc();
output();
system("pause");
return 0;
}

void input()
{

cout << "Enter your purchase price: ";
cin  >> purchasePrice;

}//end of input

void calc()
{

countyTax = purchasePrice * .02;
cin >> countyTax;
stateTax = purchasePrice * .04;
cin >> stateTax;
totalTax = stateTax + countyTax;
cin >> totalTax;
totalPrice = (stateTax + countyTax) * purchasePrice;
cin >> totalPrice;

} //end of calc

void output()
{
cout << "Your purchase cost: " << purchasePrice  << endl;
cout << "Your total county sales tax is: " <<countyTax << endl;
cout << "Your total state sales tax is : " <<stateTax <<endl;
cout << "Your total purchase cost including tax is: " <<totalPrice <<endl;

}

//end of output```
Thanks for any help in advance!

2. What compiler are you using? What do you mean it "stops?"

3. I've tried the code in Visual Studio and Bloodshed, both have given me the same result. Once executed it will allow me to enter the input for the purchase price, I hit enter, and nothing happens.

4. Code:
``` countyTax = purchasePrice * .02;
cin >> countyTax;
stateTax = purchasePrice * .04;
cin >> stateTax;
totalTax = stateTax + countyTax;
cin >> totalTax;
totalPrice = (stateTax + countyTax) * purchasePrice;
cin >> totalPrice;```
Take a close look at what this is doing...
Order of events...
What does "cin" do?

5. Take a look at calc() and those cin statements... you keep asking the user for more input

\$ ~/a.out
23
42
2
34
Your total county sales tax is: 23
Your total state sales tax is : 42
Your total purchase cost including tax is: 34

6. Wow....I'm embarrassed. I feel like my Python knowledge may have confused me due to always returning variables, however I can't explain why I was thinking "cin" was returning them for me. Thanks guys, that's one stupid mistake I'll never make again.

7. Originally Posted by Devizion
Thanks guys, that's one stupid mistake I'll never make again.
As they say...

True intellect is never making the same mistake twice...
because you're too busy making new ones.