CheshireCat
(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.
|
CheshireCat
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 10:24 AM
Response to Original message |
motely36
(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 |
tk2kewl
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 10:39 AM
Response to Original message |
CheshireCat
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 12:17 PM
Response to Original message |
|
I will post the program specs and the CH program in just a minute.
|
CheshireCat
(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);
}
|
sir_captain
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 12:43 PM
Response to Reply #5 |
|
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.
|
sir_captain
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 12:44 PM
Response to Reply #5 |
|
clearly, they want a different message for the three different results, so that portion of the program ought to be rewritten anyway.
|
CheshireCat
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 12:59 PM
Response to Reply #7 |
|
If I care even get past the syntax errors, I will add it.
|
motely36
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 12:55 PM
Response to Reply #5 |
|
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
|
CheshireCat
(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.
|
CheshireCat
(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!
|
motely36
(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 |
CheshireCat
(1000+ posts)
Send PM |
Profile |
Ignore
|
Tue Nov-30-04 01:36 PM
Response to Reply #11 |
DU
AdBot (1000+ posts) |
Thu Apr 25th 2024, 02:39 PM
Response to Original message |