for concept

hi im having trouble understanding the for concept.
this is the algorithm the teacher posted and this is the code I try to implement although im sure its not correct... I would really appreciate it if u can let me know what the true code is and explain it to me. thank you so much

// Pseudocode PLD Chapter 5 #7a, pg. 210
// // Name: Liat Ledder
// Email: ledder.liat@titans.easternflorida.edu
// Purpose:
// To create an application that gets sales transaction data for the Homestead Furniture Store.
// Start
// Declarations
// number acctNum
// string firstName
// string lastName
// number purchasePrice
// number payment
//
// output "Please enter account number: "
// input acctNum
// output "Please enter customer's first name: "
// input firstName
// output "Please enter customer's last name: "
// input lastName
// output "Please enter purchase price: "
// input purchasePrice
//
// payment = purchasePrice / 12
// output "Customer First Name: ", firstName
// output "Customer Last Name: ", lastName
// output "Account Number: ", acctNum
// for count = 1 to 12
// output "Payment Number ", count, ": $" , payment
// endfor
// Stop

#include <iostream>
#include <cstdlib>
using namespace std;
int main( )
{
int acctNum;
string firstName;
string lastName;
int purchasePrice;
int payment;
cout << “Please enter account number: “ ;
cin >> account number;
cout << “Please enter customer’s first name: “
cin >> firstName;
cout << “Please enter purchase price: “
cin >> purchasePrice;

payment= purchasePrice / 12;
cout <<“Customer First Name: “ << firstName <<endl;
cout <<”Customer Last Name: “ <<lastName <<endl;
cout << “Account Number: “ <<acctNum<<endl;


for(count = 1; count <=12; count++)
cout<<”Payment Number “
count = count+1
output count
}


system(“PAUSE”);
return 0;
}

http://www.cplusplus.com/doc/tutorial/control/

use code tags - you've lost your indentation and it's harder to read.

you seem to be incrementing count twice when you dont need to (once in your for loop and again a few lines below this).

You're doing integer division here:
payment= purchasePrice / 12;

which means that if the purchase price is 11 for example, you're payment result will be zero. which i don't think you'd want.
Last edited on
Topic archived. No new replies allowed.