No errors, but code doesnt work

Sorry if my code looks dirty, but there were just too many errors and fixing them didn't leave any room for neat. Now there are no errors in debugging but the code doesnt work still :(((
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Day random.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
int main()
{
	using namespace std;

	cout << "Welcome. Type 1 for simple interest or 2 for compound interest.\n";
	string priAmt_msg = "Please enter the principal amount ($): ",
		tim_msg = "Please enter the time in years: ",
		rte_msg = "Please enter the rate %: ";
	short choice; //To choose between simple and compound

	int principal_amt, p2;
	short time;
	double rate, r2;

	cin >> choice;

	if (choice=1)
	{
		cout << "You have chosen simple interest" << 
		endl << priAmt_msg;
		cin >> principal_amt;
		cout << tim_msg;
		cin >> time;
		cout << rte_msg;
		cin >> rate;
		cout << (principal_amt*time*(rate/100));
	}
	if (choice!=1)
	{
		cout << "You have chosen compound interest" <<
		endl << priAmt_msg;
		cin >> p2;
		cout << tim_msg;	short time, t2;
		cin >> t2;
		cout << rte_msg;
		cin >> r2;
		r2 = (r2/100);
		double tempans = (p2*(1+r2));
		cout << pow(tempans,t2);
	}
	system ("PAUSE");
	return 0;
}
Last edited on
For example I think you meant the comparison operator == instead of the assignment operator = in this statement

if (choice=1)

And instead of two if statements it would be better to write one if-else statement.
Last edited on
Works fine you just need to get rid of

#include "stdafx.h"

Also you should not use system ("pause"); really inefficient and OS dependent. I would recommend using a cin.get(); or getchar();


Edit: only works for simple interest currently
Last edited on
Thanks vlad and blancy, i see what I did wrong
Topic archived. No new replies allowed.