Jun 13, 2013 at 8:39pm UTC
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 Jun 13, 2013 at 8:48pm UTC
Jun 13, 2013 at 8:50pm UTC
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 Jun 13, 2013 at 8:52pm UTC
Jun 13, 2013 at 8:52pm UTC
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 Jun 13, 2013 at 8:55pm UTC
Jun 15, 2013 at 11:41am UTC
Thanks vlad and blancy, i see what I did wrong