-
My table program
// formatted output with cout and manipulators
#include <iostream.h>
#include <iomanip.h>
int main()
{
float principal;
float payment = 2000;
float rate;
int month = 0;
float remainder = (principal*rate)-payment;
cout << "Enter your principal: $";
cin >> principal;
cout << "Enter your rate: ";
cin >> rate;
cout << endl;
cout << "----------------------------------";
cout << endl;
cout << endl;
cout << setw(12) << "\nMonth" << setw(11) << "\nPayment" << setw(12) <<"\nRemainder\n";
cin >> remainder;
cout << setiosflags(ios::left)
<< setw(12) << ++month
<< setw(12) << payment
<< setw(12) << remainder;
cout << "\n\n";
return 0;
}
It says that my two local variable are not being initlaized.
Can soembody take a look at it and see what is wrong
Whiel you are looking at it
A user can enter any principal or payemtn or rate
but the mothns increase by one and the payment stays the same but the remainder changes
Alsothis program is suppose to output one line at a time and the next tiem the user presses any key it goes to the next line until it has completed the cxycle of 35 months.
Can anybody help me fix my mistakes!
-
--------------------Configuration: table - Win32 Debug--------------------
Compiling...
table.cpp
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(33) : error C2374: 'month' : redefinition; multiple initialization
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(16) : see declaration of 'month'
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(35) : error C2061: syntax error : identifier 'payment'
Error executing cl.exe.
table.obj - 2 error(s), 0 warning(s)
Here is my latest code
I still get 2 errors and 1 warning
// formatted output with cout and manipulators
#include <iostream.h>
#include <iomanip.h>
float repayment(float);
int main()
{
float principal;
float payment = 2000;
float rate;
int month = ++month;
float remainder = (principal*rate)-payment;
cout << "Enter your principal: $";
cin >> principal;
cout << "Enter your rate: ";
cin >> rate;
rate / 100;
rate += 1; //it should be > 1, so remaining increases
cout << endl;
cout << "----------------------------------";
cout << endl;
cout << endl;
cin >> remainder;
cout << setiosflags(ios::left)
<< setw(12) << ++month
<< setw(12) << payment
<< setw(12) << remainder;
for (int month=1; month <= 35; month++){
remainder *= rate;
if payment=remainder; //repay exactly to $0
cout << setw(12) << "\nMonth" << setw(11) << "\nPayment" << setw(12) <<"\nRemainder\n";
}
cout << "\n\n";
return 0;
}
-
update
// Rob Gross
// 3-13-02
// CS 170
#include <iostream.h>
#include <iomanip.h>
float repayment(float);
int main()
{
float principal;
float payment;
float rate;
int month = ++month;
float remainder = (principal*rate)-payment;
cout << "Enter your principal: $";
cin >> principal;
cout << "Enter your rate: ";
cin >> rate;
rate = rate/100;
rate += 1; //it should be > 1, so remaining increases
cout << endl;
cout << "----------------------------------";
cout << endl;
cout << endl;
cout << setiosflags(ios::left)
<< setw(12) << ++month
<< setw(12) << payment
<< setw(12) << remainder;
for (month=1; month <= 35; month++){
remainder *= rate;
cout << setw(12) << "\nMonth" << setw(11) << "\nPayment" << setw(12) <<"\nRemainder\n";
}
cout << "\n\n";
return 0;
}
--------------------Configuration: table - Win32 Debug--------------------
Compiling...
table.cpp
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(16) : warning C4700: local variable 'month' used without having been initialized
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(17) : warning C4700: local variable 'principal' used without having been initialized
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(17) : warning C4700: local variable 'rate' used without having been initialized
C:\Documents and Settings\Rob Gross\Desktop\WestConn\C++\Midterms\table.cpp(17) : warning C4700: local variable 'payment' used without having been initialized
table.obj - 0 error(s), 4 warning(s)
-
you haven't given any value to principal, payment, or rate before you use them in the expression that initialiizes remainder
the same with month
-
okay now my problem is this
My first line of the table does not line up and 2 I can't get the next month to find the new remainder
what I wanna do is take the principal of the next month and * rate then - the payment to get a new number.
I don't know what I am missing and i want it to go until it hits the 35th month.
Here is my code
// Rob Gross
// 3-13-02
// CS 170
#include <iostream.h>
#include <iomanip.h>
float repayment(float);
int main()
{
float principal;
float payment = 0;
float rate = 0;
float month = +1;
float remainder = 1;
cout << "Enter your principal: $";
cin >> principal;
cout << "Enter your payment: $ ";
cin >> payment;
cout << "Enter your rate: ";
cin >> rate;
rate = rate/100;
rate += 1; //it should be > 1, so remaining increases
cout << endl;
cout << "----------------------------------";
cout << endl;
cout << endl;
for (month=1; month <= 35; month++){
remainder = (principal*rate)-payment;
cout << setw(12) << "\nMonth" << setw(11) << "Payment" << setw(12) <<"Remainder\n";
cout << setiosflags(ios::left)
<< setw(12) << month
<< setw(12) << payment
<< setw(12) << remainder;
}
cout << "\n\n";
return 0;
}