1.11M Members

Program not working

 
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.
 
0
 

What's the problem?

 
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

 
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.

 
0
 

Ok, i'll try that thanks.

 
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 1 Year Ago by pritaeas and ddanbe
 
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