A forum for the users to roleplay together in various settings, e.g. historical, fantasy, or sci-fi.
HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  Register  Log inLog in  IRC channelIRC channel  

Share | 

 Programmer's thread

Go down 

Posts : 107
Join date : 2010-10-24

PostSubject: Programmer's thread   Fri Dec 17, 2010 10:40 am

As I know of at least one other beginning programmer here, this is the place to discuss programming in general and share simple programs with others.

Deza, here it is: it calculates the average of five numbers.


#include <iostream>
using namespace std;

int main()
double prinum;
double secnum;
double trinum;
double quadnum;
double quinnum;

double result;

cout << "This program will calculate the average of five numbers you enter.";
cout << "\n\n";

cout << "Enter the first number.";
cout << "\n\n ";
cin >> prinum;
cout << "\n\n";

cout << "Now enter the second number.";
cout << "\n\n ";
cin >> secnum;
cout << "\n\n";

cout << "Now enter the third number.";
cout << "\n\n ";
cin >> trinum;
cout << "\n\n";

cout << "Now enter the fourth number.";
cout << "\n\n ";
cin >> quadnum;
cout << "\n\n";

cout << "Finally, enter the fifth number.";
cout << "\n\n ";
cin >> quinnum;
cout << "\n\n";

cout << "The average of the five numbers is ";
result = (prinum + secnum + trinum + quadnum + quinnum) / 5;
cout << result;
cout << ".";

return 0;

To see a world in a grain of sand
And a heaven in a wild flower
Hold eternity in the palm of your hand
And eternity in an hour.

<superdeformedchibi> tried to think of rapture joke, but couldn't. At first I was kinda upset at my writer's block but then I realized it's not the end of the world.

Last edited by Elynae on Fri Dec 17, 2010 11:10 am; edited 1 time in total
Back to top Go down
View user profile http://nalaroth.forumotion.com


Posts : 100
Join date : 2010-10-31
Age : 22

PostSubject: Re: Programmer's thread   Fri Dec 17, 2010 11:02 am

That seems quiet good. I'll make a ruby alternative soon.
In the mean time, my bady indented maths question machine.
def hello
      puts 'whats your name'
      name = gets.chomp
      puts "Hello ". + name

def maths_question
v2 = 1 + rand(22)
v1 = 1 + rand(22)

correctA = v1.to_i + v2.to_i   
   puts "Whats the sum of #{v1} and #{v2} ?"
   youSAY = gets.chomp
   while youSAY != correctA.to_s
      puts 'Wrong, please try again.'
      youSAY = gets.chomp

def maths_congrats
   puts 'Congrats, you got the correct answer!'

puts 'Do you want to do maths questions?'
domath = gets.chomp
while domath == 'yes'

puts 'Do you want to do more?'
domath = gets.chomp
puts 'Well thats a shame, goodbye then.'
puts "Press enter to quit."

Back to top Go down
View user profile


Posts : 100
Join date : 2010-10-31
Age : 22

PostSubject: Re: Programmer's thread   Fri Dec 17, 2010 1:27 pm

Okay, the alternative of Ely's program (in ruby).


# As you can see its much more simple.

puts 'Do you want to find the average of five numbers? (yes or no)'
yesno = gets.chomp

# If the person enters anything besides yes it goes strait to the "press enter to quit"

while yesno == 'yes'
puts 'Please enter your numbers, eg. "10 20 50 70 60"'

# Gets the five numbers and splits it into a array

nt = gets.chomp.split(" ")

# Adds the numbers in the array together

ntt = nt[1].to_i + nt[2].to_i + nt[3].to_i + nt[4].to_i + nt[5].to_i

#  Divides the sum of the array by five, to find the average.
nttt = ntt.to_i/5

# The #{nttt} is a quicker way of making the nttt variable into a sperate string.

puts "The average of your numbers is #{nttt}"
puts 'Do you want to go it again?'

# If the answer = yes then it returns the user to the beginning of the loop.

yesno = gets.chomp

#  To prevent the program from exiting to quickly I've made it so the user has to enter something.

puts 'Press enter to quit.'
Back to top Go down
View user profile
Sponsored content

PostSubject: Re: Programmer's thread   

Back to top Go down
Programmer's thread
Back to top 
Page 1 of 1
 Similar topics
» Super Action Bio Thread Go!
» Official Secret Base thread!
» The Official Hate Ladonna Compson Thread
» The Kawaii Thread
» ISTJ hate thread

Permissions in this forum:You cannot reply to topics in this forum
Nálaroth :: Offtopic :: Creative-
Jump to: