Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

Help with a simple CH program

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 10:03 AM
Original message
Help with a simple CH program
I am helping my niece with a program in the language CH.

This is the first program she has been asked to do in her CS101 class. The program involves loops and IF statements, which is a bit much for a first program. She was given a few pages of notes, but no class instruction.

I downloaded "CH Standard" and started looking at it. I cannot find the error in her program and I do not know if I will have time to look at it again before she turns it in.

Can anyone her take a look at it and see if you find the error.

If so, post on this thread and I will PM you the program. It's not long or difficult.

Printer Friendly | Permalink |  | Top
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 10:24 AM
Response to Original message
1. Kick
I need your help!
Printer Friendly | Permalink |  | Top
 
motely36 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 10:37 AM
Response to Original message
2. I can look, don't know if I can help
Printer Friendly | Permalink |  | Top
 
tk2kewl Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 10:39 AM
Response to Original message
3. i will look at it
no promises
Printer Friendly | Permalink |  | Top
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 12:17 PM
Response to Original message
4. Thanks!
I will post the program specs and the CH program in just a minute.
Printer Friendly | Permalink |  | Top
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 12:27 PM
Response to Original message
5. Program specs and code

Using a while loop and a nested if statement.

When you went off to college your parents gave you a credit card. To try out the credit card, you charged some new clothes, a new laptop, and a printer. Your parents gave you enough money to pay that bill, but you used the money for something else. Winter Break came, and you took a trip to Florida. All of your expenses went on the charge card. Then came the Spring Break skiing weekend in Aspen; you needed a new skiing outfit. Who knew it would be so expensive? Staying in the lodge, equipment rentals, and those expensive restaurants all went on that credit card. You continued to use the credit card. You are almost ready to graduate, and your parents asked if you ever use that emergency credit card that you got your freshman year. Suddenly you realize that you are in debt! You have only been paying the minimum amount each month.

Write a program that will calculate the number of months it will take you to pay off the credit card debt if you quit using the credit card today.

Input:

-The amount that you owe (the balance)
-The yearly interest rate of the credit card
-The amount that you think you can pay each month

Output:

-A phrase before each input statement so that you will know which value to enter.

-The payment number and the remaining balance for each payment until the debt is paid off. Use endl so that it will be easy to read on the screen.

-A message if it will take less than a year, more than two years, or more than five years to pay off the debt.

Calculations:

-The yearly interest rate divided by 12 will give the monthly interest rate. For each month, add the monthly interest rate times the current balance to the current balance and subtract the monthly payment.



Ch Code:


#include <iostream.h>
main ( )
{
float balance, YRate, MRate, payment;
int j,i;
cls;
cout << "Enter the amount you owe on this credit card: " << endl;
cin >> balance;
cout << "Enter yearly interest rate on credit card: " << endl;
cin >> YRate;
cout << "Enter the amount you can afford to pay each month: " << endl;
cin >> payment;
MRate = YRate/12;
i = 0;
j = 1;
while(j) {
balance = ((MRate * balance)+ balance) - payment;
If (balance > 0)
i = i + 1;
else
j = 0;
}
getchar();
printf("number of months to payoff credit card is \n");
printf(i);

}


Printer Friendly | Permalink |  | Top
 
sir_captain Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 12:43 PM
Response to Reply #5
6. Seems to me
that the problem are the printf functions which won't work without stdio.h. Those are plain-vanilla C functions that probably shouldn't be mixed in with the cins and couts. Either change them to one cout statement or add an #include stdio.h to make them work.
Printer Friendly | Permalink |  | Top
 
sir_captain Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 12:44 PM
Response to Reply #5
7. Also
clearly, they want a different message for the three different results, so that portion of the program ought to be rewritten anyway.
Printer Friendly | Permalink |  | Top
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 12:59 PM
Response to Reply #7
9. Yes
If I care even get past the syntax errors, I will add it.
Printer Friendly | Permalink |  | Top
 
motely36 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 12:55 PM
Response to Reply #5
8. I think I know
if the interest rate is entered as an integer such as 12, the program will not work because your simply dividing the interest rate by 12 and then multiplying it by balance. And balance * balance -payment will never equal 0. But I tried it by entering a decimal (.12) and it worked. So either you need to make sure you enter a decimal or mod the percent.

Now I ran it on my c++ compiler and it worked.

Hope this helps
Printer Friendly | Permalink |  | Top
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 01:16 PM
Response to Reply #8
12. Here are the error messages
ERROR: missing ';'
ERROR: syntax error before or at line 38 in file 'lab7-2.ch'
==>: i = i + 1;
BUG: i<== ???
ERROR: Can't have an 'else' here
ERROR: syntax error before or at line 39 in file 'lab7-2.ch'
==>: else
BUG: else<== ??? bug may be here
ERROR: function 'If()' not defined
ERROR: cannot execute command 'lab7-2.ch'
c:/ch>

Where
-lab7-2.ch is the name of my Ch program
-My program does not have line numbers.

Would try the integer rate, but I cannot get past the syntax errors

I added

#include <stdio.h>

and

YRate = YRate/100;

The program specs require that the balance, YRate, MRate, payment be floating point.
Printer Friendly | Permalink |  | Top
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 01:02 PM
Response to Original message
10. The program must be run using a CH compiler
Meanwhile, I will make the changes suggested here and let you know the results.

Thanks again, everyone!
Printer Friendly | Permalink |  | Top
 
motely36 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 01:04 PM
Response to Reply #10
11. Sorry, I don't have one of those
Printer Friendly | Permalink |  | Top
 
CheshireCat Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Nov-30-04 01:36 PM
Response to Reply #11
13. Thanks anyway.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Tue Apr 23rd 2024, 09:18 PM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC