ok so im in college right computer science major first year and all and they still have pascal can you believe it wow so ne ways he gives out this assingment and the assingment is this i need to write a programm using delphi ythat would be able to name a prime number or a non prime number from 1 to 1000 and it needs to open the window when ran to ask you for a number and you enter a number press enter then it needs to decifer if it is a prime number or a non prime number i need help ANYONE PLEASE HELP!!!!

ok so i got some of it done i need help on the function part sooooo i find that to be the hardest ne one with ne suggestions or or ne thing

so, you think that pascal is old fashion, and you want to use delphi(you got charmed probably about drag-drop,click and the program is finished) but you aren't able to find if a number is prime or not?

what you have done until now? post some code of what you accomplished and we'll help you.

best regards,

ok so you want me to put up some code to show i know it and not just copping out or something is wut your getting out and its not that i need to know what a prime number is or if it is prime it is having the program tell me its prime .....

heres guys heres my code you guys wanted i just need help with this oother program and actually my whole class is stumped and thats why im here im lost on this im looking for help not for you guys to do it ya and thanx

Attachments
program HW4;

{ Course: CSI 1000 SP07
{ Assignment: Write a menu-driven program called hw4 that calculates the total }
{ price for a picnic lunch that the user is purchasing for a group of friends. }
{ Due Date: Due Noon Wednesday March 14.                                       }
{ Programmer: me chickenmcnugget                                                  }
{ Purpose: To get the user to make choices and see how much he would spend on a}
{ Picnic at the end of his choices.                                            }
{ Input: A or a for apple....B or b for bread.....C or c for cheese....Q or q  }
{ for quit.                                                                    }
{ Output: It produces the user with his price and choices he has chosen and the}
{ end price after he is done choosing for his or her picnic.                   }



{$APPTYPE CONSOLE}

uses
  SysUtils;
const
apples = 0.50;
breadslices = 0.25;
cheeseslices =  1.00;

 var
amt1,amt2,amt3,totalapples,totalbreads,totalcheese : integer;
quit,choice : char;
total,temp1,temp2,temp3 : real;

begin // here i begin to write out the program

// setting the vars
total := 0;
quit := 'q';
amt1 := 0;
amt2 := 0;
amt3 := 0;
totalapples := 0;
totalbreads := 0;
totalcheese:= 0;
temp1 := 0;
temp2 := 0;
temp3 := 0;


//this is a while do loop started
while (quit <> 'Q') do
BEGIN  //the start of the while do loop
//this is displaying your choice and the price of each choice
writeln ('A:  Apple .....  $0.50 each ');
writeln ('B:  Bread .....  $0.25 each ');
writeln ('C:  Cheese ..... $1.00 each ');
writeln ('Q:  Quit .....              ');

writeln;

//this displays your total while still choosing (note not end total)
writeln('Your current total is: $',total:2:2);

writeln;

//here you see the choices at which can be chosen
writeln('Enter A for apples, B for bread, C for cheese, or Q to quit');
readln(choice);

// the begin of the case statement
Case choice of
   'A':
        begin
                writeln ('How many apples would you like to buy: ');
                readln  (amt1);
                temp1 := (amt1 * apples);
                totalapples := (totalapples + amt1);
                total := (total + temp1);
                writeln ('Current total is : $ ',total:2:2);
                writeln;
                writeln;
        end;
   'a':
        begin
                writeln ('How many apples would you like to buy: ');
                readln  (amt1);
                temp1 := (amt1 * apples);
                totalapples := (totalapples + amt1);
                total := (total + temp1);
                writeln ('Current total is : $ ',total:2:2);
                writeln;
                writeln;
        end;
   'B':
        begin
                writeln ('How many bread slices would you like to buy: ');
                readln  (amt2);
                temp2 := (amt2 * breadslices);
                totalbreads := (totalbreads + amt2);
                total := (total + temp2);
                writeln ('Current total is : $ ',total:2:2);
                writeln;
                writeln;
        end;
   'b':
        begin
                writeln ('How many bread slices would you like to buy: ');
                readln  (amt2);
                temp2 := (amt2 * breadslices);
                totalbreads := (totalbreads + amt2);
                total := (total + temp2);
                writeln ('Current total is : $ ',total:2:2);
                writeln;
                writeln;
        end;
   'C':
        begin
                writeln ('How many grade A slices of cheese would you like to buy: ');
                readln  (amt3);
                temp3 := (amt3 * cheeseslices);
                totalcheese := (totalcheese + amt3);
                total := (total + temp3);
                writeln ('Current total is : $ ',total:2:2);
                writeln;
                writeln;
        end;
   'c':
        begin
                writeln ('How many grade A slices of cheese would you like to buy: ');
                readln  (amt3);
                temp3 := (amt3 * cheeseslices);
                totalcheese := (totalcheese + amt3);
                total := (total + temp3);
                writeln ('Current total is : $ ',total:2:2);
                writeln;
                writeln;
        end;
   'Q':
        begin
                writeln;
                writeln;
                quit :=  'Q';
        end;
   'q':
        begin
                writeln;
                writeln;
                quit :=  'Q';
        end
End; //right here ends the case statement go no further with case statement

END; //the loop



//here in these writeln statements is the running output total
writeln ('You purchase worth $',total:2:2,' includes the following: ');
writeln ('      Apples: ',totalapples);
writeln ('      Bread: ',totalbreads);
writeln ('      Cheese: ',totalcheese);

readln;


end.

this is it and so far nothing ne help would be appreciated please and thank you

Attachments
A prime number is a positive integer that can be divided evenly only by 1 and the number itself. Write a program that will prompt the user to enter a value up to 1000, and then will output if the number is prime or not. Values less than 3 or greater than 1000 shall be rejected.
In your program, you must write a function or procedure called prime that receives a value to check, calculates if it is prime, and returns back to the caller if the value is prime (True) or not prime (False).

Hint1: Even numbers greater than 2 are not prime.
Hint2: You only have to check for divisor values up to the square root of the number being checked. For example, if the user enters 29, you only have to check the integer values up to the square root of 29 to see if they are evenly divisible.

To help check your work, I have attached a file containing the list of primes up to 1000.















program HW5;

{Course: CSI 1000                                                              }
{Assignment: To write a program that deals with prime numbers and to write a   }
{ function called prime that has you choose a rpime number from 1 to 10000.    }
{ Due Date: Due Noon Friday March 30                                           }
{ Programmer: chickenmcnugget                                                  }
{ Purpose:Is to calculate if it is prime, and returns back to the caller if the}
{ value is prime (True) or not prime (False).                                  }
{ Input: it needs a funtcion and the program itself to be able to get the job  }
{ done plus the numbers that are prime and to 1,000                            }
{ Output: The program will output the the prime number plus it will also tell  }
{  you if it is a prime number or if it isnt a prime number.                   }
uses
  SysUtils;

 {$APPTYPE CONSOLE}
 // the start of the function
Function Prime














// the begging of thine main program

 var
num : integer;



begin
writeln(' Enter a number from  1 to 1000 and push enter ');
readln(num);




end.

SysUtils;

{$APPTYPE CONSOLE}
// the start of the function
Function Prime


// the begging of thine main program

var
num : integer;

begin
writeln(' Enter a number from 1 to 1000 and push enter ');
readln(num);


end.

this is the entire code i have found in your file! what i think? well, you made an console application which is showing a text on screen, and read an integer from keyboard.

in that file it is explained very well which is the mecanism of finding a prime number! you don't know how to implement the procedure/function or what?

best regards,

in way i do and it sounds like your bashing me and i said i needed help starting it thats what i said man and open up the other one thats there too above the one you opened so you know i know what im doing and btw man im not a top flight programmer thats why im here

you don't need to be an top programmer, you must want to learn, and try to understand. this is a very simple task which could be done if you took a delphi book, and try to accomplish it

code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
       function prime(number:integer):string;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:=prime(strtoint(edit1.Text));
end;

function TForm1.prime(number:integer): string;
var i:integer;
    prime:boolean;
begin
Label1.Caption:='';
prime:=true;
result:='prime';
if (number=1) or (number=2) or (number=3) then prime:=true
else
for i:=2 to round(sqrt(number)) do
if number mod i=0 then
 begin
  prime:=false;
  result:='not prime';
  exit;
 end;
end;

end.

hope you'll try to understand this program, not only to copy it and past it.

best regards,

Edited 1 Year Ago by Dani: Formatting fixed

thank you for your help and i am trying to learn like i said and i understand a little bit of wut you put but now that i got your help i will use my book that i have been using and see wut you did ya know anhd then figure it out that way thanx again for all your help and if i have any more qs may i ask you?

you don't need to ask me, post your questions over here, and if somebody can help then you'll receive your help

best regards,

As long as you're at it, here is how you get the program to run your Prime method when the Enter key is pressed without including a button:
1. Set the KeyPreview property of your form to True.
2. Go to the Events page of the form and double-click in the empty space to the right of the OnKeyDown event. This will create an empty method for this event.
3. In the event Delphi generates, add this code:
if Ord(Key) = VK_Return then (call your Prime function here)
Note that VK_Return is a constant defined as an integer, so you need to cast the Key value passed to your method before you can compare it to the character which you typed.

PS-They still teach Delphi in (good) schools because it is one of the best development tools for Windows and not too bad for Web and NET apps too.

This article has been dead for over six months. Start a new discussion instead.