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 ^^
program help asap please
Started by uniQue, Sep 15 2010 01:31 AM
13 replies to this topic
#1
Posted 15 September 2010 - 01:31 AM
|
|
|
#2
Posted 15 September 2010 - 05:10 AM
This sounds like homework. What do you have so far? If nothing, what part of it is confusing?
#3
Posted 15 September 2010 - 09:06 AM
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
Posted 15 September 2010 - 09:12 AM
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
Posted 16 September 2010 - 09:58 AM
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.
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
Software Developer
#6
Posted 19 September 2010 - 06:28 PM
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?
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
Posted 20 September 2010 - 03:48 PM
Why did you declare nam as integer, when you appear to want a string?
#8
Posted 21 September 2010 - 11:26 AM
because I needed to store the names in variable...
#9
Posted 22 September 2010 - 09:37 AM
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.
#10
Posted 22 September 2010 - 04:47 PM
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 )
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
Posted 22 September 2010 - 04:51 PM
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:
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
Posted 22 September 2010 - 06:14 PM
A name is not an integer, or sequence of integers. A name is a string.


Sign In
Create Account

Back to top









