i know this is jack poop to all you expert programmers out there, but I just wanted to share my last 45 minutes.. the real reason I feel good about this code i wrote is because i did the whole thing without referencing back to a tutorial, or an example (shows I'm learning something) its definitely the longest code I've written off the top of my head (even though it is SUPER short compared to an actual useful code).
also I'd like to thank the people on the forums, because I was struggling with the concept of using functions besides main, but now I've got it.. I would gladly take any tips on improving this code or tips in general! ahhh my first REAL written program. it DOES feel good
I am having trouble thinking of a way for it to loop back to main after either option is finished.. (besides exit)
Code:
#include <iostream>
#include <string>
using namespace std;
int calculator ();
int bottles_of_beer ();
int exit ();
///////////////////////CALCULATOR FUNCTIONS
double add(double x, double y)
{
return x + y;
}
double sub(double x, double y)
{
return x - y;
}
double multiply(double x, double y)
{
return x * y;
}
double divide (double x, double y)
{
return x / y;
}
////////////////////////MAIN
int main ()
{
int choice;
cout<<"This is a menu. please choose an option. (enter 1-3)\n";
cout<<"1.calculator\n";
cout<<"2.display 99 bottles of beer.\n";
cout<<"3.exit.\n";
cin>> choice;
cin.ignore();
if (choice == 1)
{
cout<< calculator();
}
else if (choice == 2)
{
cout<< bottles_of_beer();
}
else if (choice == 3)
{
int exit;
}
}
////////////////////// CALCULATOR FUNCTION
int calculator ()
{
int x=0;
int y=0;
int choice;
cout<< "please enter 2 numbers (separated by a space)\n";
cin>> x >> y;
cin.ignore();
cout<< "would you like to- \n";
cout<< "1.add\n";
cout<< "2.subtract\n";
cout<< "3.multiply\n";
cout<< "4.divide\n";
cin>> choice;
cin.ignore();
if (choice == 1)
{
cout<< "answer is " << add (x, y);
}
else if (choice == 2)
{
cout<< "answer is " << sub (x, y);
}
else if (choice == 3)
{
cout<< "answer is " << multiply (x, y);
}
else if (choice == 4)
{
cout<< "answer is " << divide (x, y);
}
cin.get();
}
///////////////////////99 BOTTLES OF BEER FUNCTION
int bottles_of_beer ()
{
int bottle_amount = 99;
while (bottle_amount > 0)
{
if(bottle_amount == 2)
{
cout<< bottle_amount << " bottles of beer on the wall, " << bottle_amount << " bottles of beer!\n";
cout<< "take one down, pass it around! " << --bottle_amount << " bottle of beer on the wall!\n\n";
continue;
}
else if (bottle_amount == 1)
{
cout<< bottle_amount << " bottle of beer on the wall, " << bottle_amount << " bottle of beer!\n";
cout<< "take one down, pass it around! " << --bottle_amount << " bottles of beer on the wall!\n\n";
continue;
}
cout<< bottle_amount << " bottles of beer on the wall, " << bottle_amount << " bottles of beer!\n";
cout<< "take one down, pass it around! " << --bottle_amount << " bottles of beer on the wall!\n\n";
}
cin.get();
}
///////////////////EXIT FUNCTION
int exit()
{
return 0;
}