I am receiving compiler errors as follows and do not know how to fix this. I know it's the same type of error, I just don't exactly know how to fix this error. Thanks in advanced!
main.cpp: In function ‘int main()’:
main.cpp:26:18: error: ‘count’ was not declared in this scope
for (count = 1; count <= 12; count ++);
^
main.cpp:28:13: error: ‘count’ was not declared in this scope
count = count + 1;
^
main.cpp:29:13: error: ‘output’ was not declared in this scope
output count;
^
After yo will notice that for loops are generally written as:
1 2 3 4
for (int count = 1; count <= 12; count++)
{
// <--- your code here.
}
The "int" allows you to define the variable count for use as a local variable in the for loop.
To what you think is in the for loop. Actually nothing because of the semicolon at the end of line 27 that should not be there. What it does is limit the for loop to just that line.
This is what your code looks line in a different way:
What is the point of line 5 in the above code? Between this and the for loop you are adding 2 to count on each iteration of the loop. Adding to count is what the third part of the for condition is for.
is from the pseudocode my homework assignment gave me. The pseudocode is as follows:
for count 1 to 12
output "Payment Number", count, ": $" , payment.
endfor
For context the assignment is designing an application that accept's a client's loan amount and monthly payment amount and outputs the loan balance each month until the loan is paid off.
But after further inspection and your feedback I understand why it doesn't make sense and I have to switch things around. Thank you again!
So you're supposed to display "Payment Number" count ": $" payment
for 12 purchases
( In your for loop you need to add braces like Andy said, but also you don't need count = count + 1 because count++ in the for parameter does that job for you. You must have been confused with while )
But where will you get the 'payment' from? Something is missing because the program accepts only 1 purchase but is asked to display 12 purchases??
Also I didn't get why "payment = purchasePrice / 12;" is being done.
And I suspect that purchasePrice is supposed to be an array. Also lastName was never assigned, you can't call it when it's not assigned.