Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

program help asap please


  • Please log in to reply
13 replies to this topic

#1 uniQue

uniQue

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

Posted 15 September 2010 - 01:31 AM

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 ^^
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

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?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 uniQue

uniQue

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

Posted 15 September 2010 - 09:06 AM

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

#4 dbug

dbug

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 148 posts

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

#5 cdg10620

cdg10620

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 344 posts
  • Programming Language:C#, JavaScript, PL/SQL, Transact-SQL, VBScript, Others

Posted 16 September 2010 - 09:58 AM

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.
  • 0
-CDG10620
Software Developer

#6 uniQue

uniQue

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

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?
  • 0

#7 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 20 September 2010 - 03:48 PM

Why did you declare nam as integer, when you appear to want a string?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#8 uniQue

uniQue

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

Posted 21 September 2010 - 11:26 AM

because I needed to store the names in variable...
  • 0

#9 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

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

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#10 uniQue

uniQue

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

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 )
  • 0

#11 uniQue

uniQue

    CC Lurker

  • Just Joined
  • Pip
  • 7 posts

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:
  • 0

#12 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 22 September 2010 - 06:14 PM

A name is not an integer, or sequence of integers. A name is a string.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download