Need help!

I have this code and the compiler is saying
<New.cpp:3:1: error: expected ‘{’ before ‘int’
New.cpp:4:1: error: expected unqualified-id before ‘{’ token
New.cpp:29:1: error: expected ‘}’ at end of input>

This is the code:
<#include <iostream>
namespace std
int main();
{
double interest_rate,loan,balance_due,balance,payment;
double actual_payment,interest_paid;
int count;

cout<<"How much do the object cost?\n";
cin>>loan;
cout<<"What is the interest rate of your credit card?\n";
cin>>interest_rate;
cout<<"How much do you pay monthly?\n";
cin>>payment;


for(count=0,balance_due>0,count++);
{
balance_due=balance-actual_payment;
actual_payment=payment-(interest_rate*balance);
balance=loan;
}
interest_paid=interest_rate*count;

cout<<"To pay $ "<<loan<<" , with your monthly payment and interest rate, would take "<<count<<;
cout<<" months, and you would have paid $ "<<interest_paid<<" in interest.\n";

return 0;
}>
Last edited on
Sometimes the error is actually before where it is reported. Be careful with your semicolons;
Hi,

<#include <iostream> -erase first <
#include <iostream>

namespace std -is: using namespace std;
using namespace std;

int main(); -erase the ;
int main()

for(count=0,balance_due>0,count++); -replace , for ; -erase last ;
for(count=0; balance_due>0; count++)

[...]payment and interest rate, would take "<<count<<; -erase last <<
[...]payment and interest rate, would take "<<count;

return 0; }> -erase last >
return 0; }


* In the code, balance is not assigned before is used,
this is a important logical error:
balance_due=balance-actual_payment;

Regards,

-
dalazul.


I fix it but i got an infinite loop, can you help me
This is the loop body:
for(count=0;balance_due>0;count++)
{
balance=loan;
actual_payment=payment-(interest_rate*balance);
balance_due=balance-actual_payment;
}
Hi Weliot,

you can see the problem debugging the source, and watching
the contents of vars with control above the final condition of the loop.
I'm also starting with c++, but try:

1
2
3
4
5
6
7
8
9
        balance=loan;
	balance_due=loan;
	
	for(count=0; balance_due>0; count++)
	{
		actual_payment=payment-((interest_rate*balance)/100);
		balance_due-=actual_payment;
	}
        interest_paid=interest_rate*count;



Regards,

--
dalazul
weliot, next time you post code put

[ code]
your code goes here
[ /code]
dont use the spaces between [ code and [ /code though.

im just letting you know, because i know some people get frustrated when the coding is not neat and more readable like the example dalazul showed, im not trying to be mean or anything, just trying to give you a heads up.
Last edited on
Thanks to all that help me i'm gona try to put the code nicely next time. And i'm gonna try to debbug because i forgot how to
Topic archived. No new replies allowed.