Jump to content

program help asap please

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
uniQue

uniQue

    Newbie

  • Members
  • Pip
  • 7 posts
Q: Write a program that inputs the names and cost prices of 10 items. Determines the name of the most expensive item and outputs the name of the most expensive item.

TYVM for any help ^^

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
This sounds like homework. What do you have so far? If nothing, what part of it is confusing?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
uniQue

uniQue

    Newbie

  • Members
  • Pip
  • 7 posts

WingedPanther said:

This sounds like homework. What do you have so far? If nothing, what part of it is confusing?

yep it is homework.

I don't actually have anything but what I can't quite figure out is what to do to determine the most expensive one. Like I was thinking you'd probably use while loop to keep track of how many names and cost prices were entered but as to how exactly to find the most expensive :confused: no clue.

#4
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
One way to do this is to memorize the cost of the most expensive item (you start with 0 when you don't have any item) and compare this cost with every input item. If it's greater, update the memorized cost and save the name of the product to show it later.

#5
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts

uniQue said:

yep it is homework.

I don't actually have anything but what I can't quite figure out is what to do to determine the most expensive one. Like I was thinking you'd probably use while loop to keep track of how many names and cost prices were entered but as to how exactly to find the most expensive :confused: no clue.

You do realize that we're not a glorified tutoring service right?! We don't do homework for you. We are here to help you. Post some code and then get back to us.
-CDG10620
Software Developer

#6
uniQue

uniQue

    Newbie

  • Members
  • Pip
  • 7 posts
lol yeah Ik, I'm sorry. Wanted an easy way out :/
But as it turns out my teacher moved on. He gives us like two at a time, i did the other one so I didn't have to do that one.

Now I have a new one.....I'm having a bit of trouble. I'm not the best with arrays and now this one involves strings. I did a lot, totally thought I was onto something...lol turns out I wasn't.

Basically you have to input the names of 5 students and marks for each and then output it like eg. Jack got 40....or something like that.

Program MarkSystem;

var Name:Array[1..30] of string[20];
Marks:Array[1..30] of integer;
count,nam,mark: integer;

begin
count:= 0;
while (count<=5) do
begin
writeln('Please insert the first name of a student');
readln(nam);

writeln('Please insert a mark for the student');
readln(mark);

Marks[count]:= mark;

Name[count]:= nam;

count:= count+1;

end;


end.


That's all I got so far...something's off, it won't even run. And yeah i have quite figured out how to output the name with the corresponding mark.... help?

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Why did you declare nam as integer, when you appear to want a string?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
uniQue

uniQue

    Newbie

  • Members
  • Pip
  • 7 posts
because I needed to store the names in variable...

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
nam is waiting for you to type a number, because it is an integer. You CANNOT type something like "Mary" and have it accepted as an integer value.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
uniQue

uniQue

    Newbie

  • Members
  • Pip
  • 7 posts
omg...DUH....i feel like an idiot now...ugh.
of course I cant store a name in a variable I declared as an integer...ugh.
ok so I think I see what you're saying, I'm going to have to read it into the array then? do I just write
writeln('Please insert the first name of a student');
readln(Name);

instead and it will work??
(I shall go try it now :D )

#11
uniQue

uniQue

    Newbie

  • Members
  • Pip
  • 7 posts
ok that didnt work....I had

Program MarkSystem;


var Name:Array[1..30] of integer;
Marks:Array[1..30] of integer;
count, mark: integer;

begin
count:= 1;
while (count<=5) do
begin
writeln('Please insert the first name of a student');
readln(Name);

writeln('Please insert a mark for the student');
readln(mark);

writeln('The names and marks of the students', Name:Array, Marks:Array);


Marks[count]:= mark;



count:= count+1;

end;


readln;
end.


am I suppose to read it as 'Name:Array' or something?? :confused:

#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
A name is not an integer, or sequence of integers. A name is a string.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog