Math and decimals?

Alright, so I'm using bloodshed Dev-C++ but I don't think that's the problem. I'm trying to make a short program that will summarize how much money in USD I will have when I finish working here in China. I think the problem lies within my source code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;
int main()
{
    double yuan; 
    double dollar;
    double months;
    dollar = 68275;
    yuan = 1465;
    cout << "How long will you live in China? How many months?" << endl;
    cin >> months;
    cout << "How much money do you make each month?" << endl;
    cin >> yuan;
    cout << "You will have " << (months * yuan) * dollar << " dollars when you go back to America." << endl;
    system("PAUSE");
    return 0;
}


for the first cin, I punch in "36" in the console.

Then when it asks how much money I make each month, I punch in "12000" (chinese yuan).

the answer it spits out is well, let me take a screen-shot of it...
http://i277.photobucket.com/albums/kk77/Forb1dden117/programming%20n%20stuff/error.jpg
Well, it wouldn't be too bad for you if your program was right :D

Anyway, you're storing values in doubles. Try either to enter "36.0" and "12000.0" or to store the input values in integers.
at line 10, you define yuan. At line 14, you ask the user to input it again. Also, you're missing a decimal when you define dollar at line 7, hence the gigantic numbers.

EDIT: Corpus types faster than I do.
Last edited on
Topic archived. No new replies allowed.