I'm not sure this will post in a readable format, so I apologize in advance for that. (I read how to input it, but my computer is not showing the (#) edit symbol anywhere.
I am getting a lot of warnings and several "uninitialized local variable" errors for every one of my input variables. I've not had this issue before, I'm assuming it's because I've done the looping incorrectly.
This is only for Chapters 1-6, so we are NOT allowed to use anything more complex than the basics, up through the use of While loops. He is specifically asking for While loops.
This is what I get when I run the program:
(29,29): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
(30,35): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
(32,41): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
(44,10): warning C4804: '>': unsafe use of type 'bool' in operation
(29): error C4700: uninitialized local variable 'annualIntRate' used
(31): error C4700: uninitialized local variable 'price' used
(31): error C4700: uninitialized local variable 'downPayent' used
(31): error C4700: uninitialized local variable 'tradeIn' used
(32): error C4700: uninitialized local variable 'noMonths' used
I am asking for specific inputs and have identified them in the beginning, I've searched the forums and the web and have been unable to figure out what I did wrong.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
//*******************************************************************************************
//
// Midterm
// This program is designed to calculate the monthly car payments for a customer
//
//*******************************************************************************************
#include <iostream>
#include <iomanip> // for setwidth
#include <cmath>
using namespace std;
int main()
// Input Variables and formulas
{
float price; // price of vehicle
float downPayent; // down payment
float tradeIn; // trade in value
float loanAmount; // loan amount (calculated)
float annualIntPercent; // annual interest percent (calculated)
float annualIntRate; // annual interest rate (calculated)
int noMonths; // number of monthly payments (12, 24, 36, 48, 60)
float monPayment; // Monthly payment (calculated)
float monIntRate; // monthly interest rate (calculated)
int i=1; // count initializer for needed information.
int e = 6; // will be used to end and restart program
monIntRate = annualIntRate / 12.0;
annualIntPercent = annualIntRate * 100.0;
loanAmount = price - downPayent - tradeIn;
monPayment = (loanAmount * monIntRate) / (pow(1.0 - (1 + monIntRate), -noMonths));
// Get Price loop
cout << "Please enter price of vehicle" << endl;
cin >> price;
while (i==1)
{
while (price > 50.00 || price < 50000.00)
cin >> price;
i++;
while (!price > 50.00 || price < 50000.00)
cout << "Incorrect price entered. Please make sure you use decimal format, with no comma.<<endl; (example: 25,000 would be entered as 25000.00)<<endl;<<endl;<< Price must be greater than $50.00 and less than $50,000.00<<endl;<<endl; Please enter the number 6 to restart" << endl;
cin >> e;
while (e==6)
return 0;
}
while (i == 2)
{
cout << "Please enter trade in value" << endl;
cin >> tradeIn;
{
while (tradeIn >= 0 && tradeIn < price)
cin >> tradeIn;
i++;
}
}
while (i == 3)
{
cout << "Please enter down payment" << endl;
cin >> downPayent;
{
while (downPayent >= 0 && downPayent < (price - tradeIn))
cin >> downPayent;
i++;
}
}
while (i == 4)
{
cout << "Please enter annual interest rate.<<endl;<<Interest rate must be entered in fraction format<<endl;<<(example: 6% would be entered as .06)<<endl;<<endl;<< Annual interest rate must be greater than, or equal to, 0, and be less than .50" << endl;
cin >> annualIntRate;
{
while (annualIntRate >= 0 && annualIntRate < .50)
cin >> annualIntRate;
i++;
}
}
while (i == 5)
{
cout << "You're monthly payment for a 12 month loan is: " << monPayment << 12;
cout << "You're monthly payment for a 24 month loan is: " << monPayment << 24;
cout << "You're monthly payment for a 36 month loan is: " << monPayment << 36;
cout << "you're monthly payment for a 48 month loan is: " << monPayment << 48;
cout << "you're monthly payment for a 60 month loan is: " << monPayment << 60;
i++;
}
while (i == 6)
{
cout << "Vehicle Price: " << price;
cout << "Trade in Value: " << tradeIn;
cout << "Down Payment: " << downPayent;
cout << "------------------------------------";
cout << "Loan Amount: " << loanAmount << endl;
cout << endl;
cout << "Annual Interest Rate: " << annualIntPercent;
i++;
}
while (i == 7)
{
return 0;
}
}
|