Ok, hi guys.... I have some IT homework due tomorrow and I honestly don't know what to do. I've made multiple attempts and it's just not working out for me. So I'm asking for help ASAP PLEASE. The questions states:

Write a program to read in the names of a sequence of products and their price. The program terminates when a "0" price for a product is encountered. The program should print the number of items purchased and a grand total. The data will be entered in the following format: Product, Price, Product, Price, Product, Price.

Please guys it goes towards my semester grade :)

Dani AI

Generated

For : the task is simplest when the program reads a product name (allowing spaces), then a numeric price, repeats that pair until a price of 0 is entered, and then prints the item count and grand total. As suggested, posting an attempt helps; is right that effort matters; thanks to for offering support. Below is a compact, beginner-friendly Pascal solution that assumes one product/price pair per interaction (remove the prompts if the grader expects raw input).

program ProductTotals;
var
  product: string;
  price: Real;
  count: Integer;
  total: Real;
begin
  count := 0;
  total := 0.0;
  writeln('Enter product name then price. Enter price 0 to finish.');
  repeat
    write('Product: ');
    readln(product);      { allows names with spaces }
    write('Price: ');
    readln(price);
    if price <> 0.0 then
    begin
      Inc(count);
      total := total + price;
    end;
  until price = 0.0;
  writeln('Number of items purchased: ', count);
  writeln('Grand total: ', total:0:2);
end.

Key points and quick troubleshooting:

  • Use readln for the product so spaces are preserved; read can leave trailing input.
  • Do not increment count or add price when the terminating 0 is read.
  • Format the total with :0:2 to show two decimals. If the auto-grader provides all pairs on a single comma-separated line, parse the line (split on commas) or read tokens without prompts and adapt the loop accordingly.
  • Common pitfalls: forgetting to exclude the sentinel 0, locale decimal-separator issues (some systems expect comma instead of dot), and mismatching exact output text when an assignment requires it.

If exact input/output formatting for submission is required, remove prompts and match the sample I/O the grader expects.

Recommended Answers

All 3 Replies

What do you have so far? (Starting to ask questions on your last day is a little late too IMHO.)

I've helped with someone's homework here and won't do it again. You'll find that you won't get much help if you want someone to do your homework for you. Best case scenario, post the code you've been working on and someone might point you in the right direction.

If you still need an answer just ask but i'm assuming I may be to late

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.