1
Off Topic / Re: WhatevaGuy is learning C++!
« on: June 05, 2011, 09:12:50 PM »I predict a precision error
Use only whole numbers
What do you mean? :o
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I predict a precision error
Use only whole numbers
//Lists square numbers up to a user-defined point.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs)
{
//Set up all necessary variables.
int square;
int root;
int additive;
int limitdecision;
int limit;
//Define a few variables.
square = 0;
root = 0;
additive = 1;
cout << "Would you like a (0) root- or (1) square- limit? ";
cin >> limitdecision;
switch (limitdecision)
{
case 0:
break;
case 1:
break;
default:
return 0;
}
cout << "Please enter the limit for the square numbers: ";
cin >> limit;
limit += 1;
//Loop time!
if (limitdecision == 0)
{
while (root < limit)
{
cout << square << " - " << root << endl;
square += additive;
root += 1;
additive += 2;
}
system("PAUSE");
return 0;
}
if (limitdecision == 1)
{
while (square < limit)
{
cout << square << " - " << root << endl;
square += additive;
root += 1;
additive +=2;
}
system("PAUSE");
return 0;
}
}
//Lists square numbers up to a user-defined point.
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs)
{
//Set up all necessary variables.
int cube;
int root;
int additive1;
int additive2;
int limitdecision;
int limit;
//Define a few variables.
cube = 0;
root = 0;
additive1 = 1;
additive2 = 6;
cout << "Would you like a (0) root- or (1) cube- limit? ";
cin >> limitdecision;
switch (limitdecision)
{
case 0:
break;
case 1:
break;
default:
return 0;
}
cout << "Please enter the limit for the cubed numbers: ";
cin >> limit;
limit += 1;
//Loop time!
if (limitdecision == 0)
{
while (root < limit)
{
cout << cube << " - " << root << endl;
cube += additive1;
additive1 += additive2;
additive2 += 6;
root += 1;
}
system("PAUSE");
return 0;
}
if (limitdecision == 1)
{
while (cube < limit)
{
cout << cube << " - " << root << endl;
cube += additive1;
additive1 += additive2;
additive2 += 6;
root += 1;
}
system("PAUSE");
return 0;
}
}
//Collatz Conjecture - 1 can be derived from any integer if, while the integer is even,
//it is divided by two and, if it is odd, it is multiplied by three and increased by one.
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <windows.h>
using namespace std;
int collatzConjecture()
{
int num;
cout << "Please enter a number: ";
cin >> num;
system("CLS");
//as long as the number is NOT one
while(num != 1)
{
//output the number for client
cout << num << endl;
//check if the number is odd or even
bool oddeven;
oddeven = (num % 2 == 0);
//take certain action, depending on whether num is odd or even
switch(oddeven)
{
case 1:
num = num/2;
break;
case 0:
num = (num*3) + 1;
break;
}
}
cout << "1\n\n";
cout << "Done!\n\n";
system("PAUSE");
return 0;
}
void collatzConjectureTwo()
{
//setup...
string oper;
int delay;
int num2;
cout << "Starting number: "; //ask for starting number
cin >> num2;
cout << "Delay (millisecs): "; //ask for delaytime
cin >> delay;
//loop forever (unless user inputs 0 or less..)
while (num2 > 0)
{
//clearscreen
system("CLS");
int num1 = num2; //set number1 to be number 2
oper = "start"; //make sure this always reads 'start' on the first time
while(num1 != 1) //as long as number1 is not 1..
{
cout << num1 << " - " << num2 << " - " << oper << endl; //output EVERYTHING
Sleep(delay); //sleep for however long user wants
bool oddeven; //test whether or not the number is even
oddeven = (num1 % 2 == 0); //this is not the work of me, by the way, so don't go giving me credit for this line. the rest is me though
switch(oddeven)
{
case 1: //if even, divide by two
num1 = num1/2;
oper = "n/2";
break;
case 0: //if odd, multiply by three and add 1
num1 = (num1*3) + 1;
oper = "3n+1";
break;
}
}
cout << "1 - " << num2; //finish it up
system("CLS");
num2 += 1; //add one two num2 so we can do the same thing with the next number :D
}
}
int main(int nNumberofArgs, char* pszArgs[])
{
int collatzchoice;
cout << "Collatz Conjecture 1 (1) or 2 (2)? ";
cin >> collatzchoice;
switch(collatzchoice)
{
case 1:
system("CLS");
collatzConjecture();
return 0;
case 2:
system("CLS");
collatzConjectureTwo();
}
}
Jamestown? lol
You seem like you need something to be mad about. The increase in the amount of people with arthritis looks like about 50%. The actual population will not grow that fast.
god dammitI don't recognize it, I just tineyed one of the little skulls :P
also it was localized :c
it isnt TOO japanese
okay its really japanese
i doubt many people will know what this skull design in particular is from
what could that one blurred out thing be...