Selection String

I am in Intro to Programming C++ and have a homework assignement. In my last class we had a sub, so things weren't explained as good as it could have been with the Prof. She gave no examples of code. So I am completely lost how to declare the variables for codes with if/else statements.

The program has to allow me to enter dollar amounts and give change. Can someone explain to me what i am to do in declaring the variables when I am to use quarters, dimes, nickels, and pennies? Just please remember it is an intro class so I am not experienced and able to understand when you talk technical.
closed account (zb0S216C)
Variables are simple, so are if statements. Here's a quick overview of both of them:

Variables

A variable (Datum) is an instantiation of either a built-in type or user-defined type. All variables reserve a set amount of bytes (ranging from 1-n. Where n is the largest of user-defined and built-in types in bytes) within the computer’s memory. The type-specifier of a variable indicates the variable’s type. The type-specifier is used to determine the type of value that can be stored within the variable. It’s the type-specifier that gives the variable its size (without the type-specifier, how would we know the size of the datum?). For example, according to the C++ standard, a variable that is of type int should at least reserve 4 bytes of memory. The Symbol of a variable is an alias for the region of memory that is the variable. The symbol of the variable doesn’t contribute to the size of a variable. The memory address of the first byte of a datum is considered the address of the entire datum.

If Statement

The if statement is a control structure. Each statement has a condition. If the condition evaluates to true, the statements within the following braces ({...}) are executed one by one. If the condition evaluates to false, the statements are ignored. Conditions always evaluate to either true or false, and nothing else. if statements can be nested, which means an if statement within the body of another if statement. Following an if statement are two related statements, called else if and else. else if must be proceeded by an if statement. else if and else are optional.

For further reading see these links:
if statements: http://www.cplusplus.com/doc/tutorial/control/
Variables: http://www.cplusplus.com/doc/tutorial/variables/

Wazzak
Last edited on
Topic archived. No new replies allowed.