This is the algorithm that I am working from

Algorithm Name: UPDATE_CHECKBOOK
Problem Input(s):
start_balance - the beginning checkbook balance.
xact_amount - the amount of the transaction.
xact_type - the type of the transaction (credit or debit).
Problem Output(s):

new_balance -- the ending checkbook balance.
Relevant Formula(s):

Adding a credit = (starting balance) + (transaction amount)
Subtracting a debit = (starting balance) - (transaction amount) Algorithm:
BEGIN
Ask the user for the starting balance.
Input the starting balance (start_balance).
Ask the user for the transaction amount.
Input the amount of the transaction (xact_amount).
Ask the user for the type of transaction.
Input the type of transaction (xact_type).
If (the value of xact_type is "Credit") Then
Compute new_balance = (start_balance + xact_amount).
Else
Compute new_balance = (start_balance - xact_amount).
End If
Output the desired value (new_balance).
END

This is what I have so far. I don't know if this is right or not

Note: I AM VERY NEW TO THIS. I AM LEARNING IT NOW
int main()
{
int start_balance, xact_amount, xact_type;
int new_balance;

cout << "Please the starting balance: ";
cin >> start_balance;
cout << "Please enter the transaction amount: ";
cin >> xact_amount;
cout << "Please enter the type of transaction: ";
cin >> xact_type;
if
(xact_type = credit) {new_balance = start_balance + xact_amount;}
else
(xact_type = debit) ;{new_balance = start_balance - xact_amount;}

You are using int to store what most likely would be a floating point number (I have $4.82 in my account so I'd enter 4.82).

You are using int to store a string (xact_type) and comparing it to something that doesn't exist "credit, debit". You are also using the assignment operator '=' instead of the compare '==' operator.

so where would I put float at . Would it go next to main or next to star_balance etc...

can you show me what the right answer would be to the alogrithm.. if not can you explain more in detail about the first answer you gave me...
(You are using int to store a string (xact_type) and comparing it to something that doesn't exist "credit, debit". You are also using the assignment operator '=' instead of the compare '==' operator.)

IM VERY NEW TO THIS

I know you are new, I'm just trying to point out problems rather than give you the answer. It is my belief you learn more from figuring thing out rather than someone giving you the answer.

That said, the variables start_balance, xact_amount and new_balance should probably be floating point numbers. You declare them here:

int start_balance, xact_amount, xact_type;
int new_balance;

So you'd need to replace the int with float (but you'll still need to deal with xact_type being a string (hint) rather than a number).

As for the last part of my statement, when you want to compare values you use the == operator. The = operator means "make the left hand side equal to the result of the right hand side".

commented: True +6

Okay this is what I have so far

int main()
{
float start_balance, xact_amount, xact_type, new_balance;

cout << "Please the starting balance: ";
cin >> start_balance;
cout << "Please enter the transaction amount: ";
cin >> xact_amount;
cout << "Please enter the type of transaction: ";
cin >> xact_type;
if
(xact_type == xact_type)
new_balance = start_balance + xact_amount;
else
new_balance = start_balance - xact_amount;

cout << " You're new balance " << new_balance << "!" << endl;


}

Now to make xact_type a string rather than a number would I change that in the float statement or in the function part of the program. That is part I'm have a problem with now. Also from what I have written I can get it to add when entering "credit" but when I enter debit it still adds, but I want it to subtract

In the float statement. You'll want to put it on it's own line because it isn't a float :)

The reason for the always add is that xact_type == xact_type is always true. You'll want to computer it to "credit"

would this be what I'm supposed to use

string my_string("staring value");

I doubt you can even get it to compile, since you haven't included the proper headers for "cout" and "cin"


Also, xact_type will always be equal to itself, your if statement is not doing anything. You had the right idea the first time, just the wrong syntax. You need to place your comparison strings in quotes " ". You still need to declare xact_type as a string, and not a float.

How do I declar xact_type as a string. I was looking and found this string str; but I don't know if this is correct

can somebody just give me the answer. This is an assignment thats due Mon.. I just need the part that allows me when I enter Credit it adds, and when I enter Debit it will subtract... PLEASE!

#include <string> (you still don't have #include <iostream> listed in your code either). It's likely when you found string str; that "str" was a specific variable from someone's code. How would you declare any other variable that is of type XYZ? Nothing special for strings.

It's not good form to beg people to fix something for you. No one is going to give you the answer. In reality, you have all the answers you need to solve this, you just need to think about what you are doing and bring it all together.

Alright this is what I have. I don't mean to come off begging but I have been working on this all day and its starting to frustrate me, but this is what I have can you atleast just tell me whats wrong with it


#include <iostream>
#include <string>
using namespace std;

int main()
{
float start_balance, xact_amount, new_balance;
string xact_type;


cout << "Please the starting balance: ";
cin >> start_balance;
cout << "Please enter the transaction amount: ";
cin >> xact_amount;
cout << "Please enter the type of transaction: ";
cin >> xact_type;
if
(xact_type == xact_type)
new_balance = start_balance + xact_amount;
else
(xact_type == xact_type)
;new_balance = start_balance - xact_amount;

cout << " You're new balance " << new_balance << "!" << endl;


}

if(xact_type == ???)

Why do you keep wanting to find out if it's equal to itself?? Of course it's equal to itself. You want to find out if it's equal to a certain string. See if it's equal to that string. Also, else doesn't need any expression with it. Else is what covers anything that doesn't fall under the other conditions.

so would I make it if statement if (xact_type == Credit)

I have the string set to xact_type would I make that Credit. If so where would I put xact_type. The person in the forum told me to take it from the float statement

You've got xact_type where it's supposed to be now, he was saying take it out of the variables you were declaring as floats. That's all squared away.

You're getting closer, but how do you write a string constant -->> " "
you didn't write

cout <<Please enter the starting balance;

so why would you write

xact_type == credit

I did write it
cout << "Please enter the starting balance: ";

I'm not understanding your question
how do you write a string constant -->> " "

and am I supposed to delete (xact_type == Credit) from the if statement

Okay, so I'm asking you why you need the quotes on the string constant "Please enter the starting balance" and not on the string constant "credit." It's the same idea. You need them both. credit is a variable named credit, "credit" is a string constant equal to the word credit. You want to compare xact_type to "credit", not to credit.

So is this correct so far?

#include <iostream>
#include <string>
using namespace std;

int main()
{
float start_balance, xact_amount, new_balance;
string xact_type;

cout << "Please enter the starting balance: ";
cin >> start_balance;
cout << "Please enter the transaction amount: ";
cin >> xact_amount;
cout << "Please enter the type of transaction: ";
cin >> xact_type;
if (xact_type == "credit")
new_balance = start_balance + xact_amount;
else
new_balance = start_balance - xact_amount;

cout << " You're new balance " << new_balance << "!" << endl;


}

Yes, but you can test it out for yourself, too.

It WORKS.....

THANK YOU!!!!!
(had to take a chill pill) and followed your instructions THANKS

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.