Jump to content

Finding the sum, product...

- - - - -

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

#1
Lesser_Intellect

Lesser_Intellect

    Newbie

  • Members
  • PipPip
  • 16 posts
Could someone help me with this please.

Write a program that will prompt the user for three integers. The program should then find the difference between the largest and smallest integers. The program should also calculate the sum of the three inegers and also their product and average. Display to the user difference, sum, product and average.
N.B The user should not be able to enter the same number more than once. Your program should be user friendly.

Print "Greetings"
Process_three_integers_of_different_values
INPUT "Please enter an integer."
N1
INPUT "Please enter another different integer."
N2
INPUT "Please enter another different integer."
N3

set sum to zero

IF (N1>N2 & N1>N3)

largest=N1;

ELSE IF(N2>N3 & N2>N1)

largest=N2;

ELSE
largest=N3;

IF(N1<N2 & N1<N3)

smallest=N1;

ELSE IF(N2<N3 & N2<N1)

smallest=N2;

ELSE
smallest=N3;

difference = largest - smallest
sum = N1 + N2 + N3
product = N1*N2*N3
average = sum/3

Edited by Lesser_Intellect, 01 November 2009 - 03:43 PM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
What is your question? It doesn't fully meet the requirements, but it's not clear what you want help with.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Lesser_Intellect

Lesser_Intellect

    Newbie

  • Members
  • PipPip
  • 16 posts
Where it starts "write a program"... I just want my program checked, please.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You haven't enforced entering three different numbers.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Lesser_Intellect

Lesser_Intellect

    Newbie

  • Members
  • PipPip
  • 16 posts
Thanks. I don't know how to 'enforce' it.

Print "Greetings"
Process_three_integers_of_different_values
INPUT "Please enter an integer."
N1
INPUT "Please enter another different integer."
N2
INPUT "Please enter another different integer."
N3

set sum to zero
set largest to N1
set smallest to N1

IF (N2>largest)

largest=N2;

IF(N3>largest)

largest=N3;

IF(N2<smallest)

smallest=N2;

IF(N3<smallest)
smallest=N3;
ENDIF
ENDIF
ENDIF
ENDIF

difference = largest - smallest
sum = N1 + N2 + N3
product = N1*N2*N3
average = sum/3
Display difference, sum, product, average.
END

#6
Natrobius

Natrobius

    Programmer

  • Members
  • PipPipPipPip
  • 166 posts
What winged is saying is that your program does not check to make sure that the input received from the user is a valid number, instead of a character or the like. You need to add code to validate the user input or your program may crash when incorrect input is received. At the very least it will give unpredictable results.

#7
Lesser_Intellect

Lesser_Intellect

    Newbie

  • Members
  • PipPip
  • 16 posts

Natrobius said:

What winged is saying is that your program does not check to make sure that the input received from the user is a valid number, instead of a character or the like. You need to add code to validate the user input or your program may crash when incorrect input is received. At the very least it will give unpredictable results.

How do I check to make sure that the input received from the user is a valid number?

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You'll have to use a while loop for each input after the first, checking to make sure you don't have duplicate values.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
Lesser_Intellect

Lesser_Intellect

    Newbie

  • Members
  • PipPip
  • 16 posts
Print "Greetings"
Process_three_integers_of_different_values
INPUT "Please enter an integer."
N1
WHILE N1 > 0
INPUT "Please enter another different integer."
N2
WHILE N2 > 0
INPUT "Please enter another different integer."
N3
WHILE N3 > 0

set sum to zero
set largest to N1
set smallest to N1

IF (N2>largest)

largest=N2;

IF(N3>largest)

largest=N3;

IF(N2<smallest)

smallest=N2;

IF(N3<smallest)
smallest=N3;
ENDIF
ENDIF
ENDIF
ENDIF

difference = largest - smallest
sum = N1 + N2 + N3
product = N1*N2*N3
average = sum/3
Display difference, sum, product, average.
END

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Not quite:
Print "Greetings"
Process_three_integers_of_different_values
INPUT "Please enter an integer."
N1
do 
  INPUT "Please enter another different integer."
  N2
until N2 <> N1
do
  INPUT "Please enter another different integer."
  N3
until n3 <> n2 and n3 <> n1

set sum to zero
set largest to N1
set smallest to N1

IF (N2>largest)

largest=N2;

IF(N3>largest)

largest=N3;

IF(N2<smallest)

smallest=N2;

IF(N3<smallest)
smallest=N3;
ENDIF
ENDIF
ENDIF
ENDIF

difference = largest - smallest
sum = N1 + N2 + N3
product = N1*N2*N3
average = sum/3
Display difference, sum, product, average.
END

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

#11
Lesser_Intellect

Lesser_Intellect

    Newbie

  • Members
  • PipPip
  • 16 posts
What area needs correction?
I'm kinda guessing and spelling since I'm clueless to computer programming.

#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Look at the changes I made to your code.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog