1,105,177 Community Members

Program not working

Member Avatar
HelpWanted2115
Newbie Poster
11 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok, so I got a program to do in TurboPascal but it's not doing the one of the requirements and I'm not sure how to get it so the question states: Write a program to read in the names of a sequence of products and their price. The program terminates when a 0 price is encountered for a product. The program should print the number of items purchased and a grand total. The data will be entered in the following order: Product,Price,Product,Price...

This is what I have so far:

program sequence;

uses wincrt;

var price,count,pre_sum,new_sum,sum,new_price:integer;product:string;

Begin

 count:=1;
 readln(Product);
 readln(Price);
 While price<>0 do
 Begin
      readln(Product);
      readln(Price);
      sum:=Price+Price;
      count:=count+1;
      Writeln('Grand Total: ',sum);
      Writeln('The number of items purchased is ',count);
 End;

End.
Member Avatar
pritaeas
mod_pritaeas
11,303 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,833 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

What's the problem?

Member Avatar
HelpWanted2115
Newbie Poster
11 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

It's suppose to add all the prices together, but once i go more than 2 prices for 2 products, it gives me incorrect numbers, im trying to get a grand total each time a product is entered for eg. Ham-500,Chicen-500 Grand Total=1000 or Ham-500,Chicken,200,Rice-300...Grand Total=1000 but it just wont add the third price with the previously entered prices

Member Avatar
ddanbe
Posting Expert
5,345 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 906 [?]
Skill Endorsements: 46 [?]
Featured
 
1
 

I should init sum to zero before the while and line 16 should read sum := sum + Price;
EDIT: ho, count should also be initialised to zero.

Member Avatar
HelpWanted2115
Newbie Poster
11 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Ok, i'll try that thanks.

Member Avatar
HelpWanted2115
Newbie Poster
11 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Your idea worked!!! Just that it needed a bit of adjusting :D(initializing sum:=Price;before while) thanks much man thanks!!! If you have the time could you check out my other post? Title is "This doesn't make sense"... Thanks again.

Question Answered as of 11 Months Ago by pritaeas and ddanbe
Member Avatar
HelpWanted2115
Newbie Poster
11 posts since May 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Nevermind, you guys already did :D

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article