Thumbs upMy first c++ program!

Posts 1–15 of 32 · Page 1 of 3
My first c++ program!
Hey guys, so this is what it does:
it squares any number you want. ( doubles it)
Dont QQ how bad it is since its my first prog.

Source code:
Code:
#include <iostream>
int main()
{
    using namespace std;
    int mynumber, myothernumber;
    cout << "What number do you want to make squared?" << endl;
    cin >> mynumber;
    cout << "Really dude? That number? your brain too small to make it squared yourself? Fine than... press any key to see your answer if you still havent figured it out. ";
    mynumber = mynumber * mynumber;
    system("pause");
    cout << mynumber << endl;
    system("pause");
    return 0;
}
It's decent, yes.

I would just advice you to use the "using directive" (use namespace std; ) outside of the main scope. (not only on the main function, so it applies that namespace on the whole program)

And name your variables a little better. (But since you just started...)
And always initialize variables too. (Even with 0)
jabuuty i will remove the attachment anyways. I posted a sc anywsys.
Brinuz thx. I didnt understand your post but im sure i will when i learn more.
Quote Originally Posted by Ronon666 View Post
jabuuty i will remove the attachment anyways. I posted a sc anywsys.
Brinuz thx. I didnt understand your post but im sure i will when i learn more.
variables is what hold values.
In your case: mynumber, myothernumber
thx jabuuty, brinuz, i know what variable is but i didnt understand the initializing thing. Anyways i made the program as perfect as i could! This time i made a ss and virus scan.

i dunno why i posted the attachment but it just seemed so cool for my first prog. (I have only been learning for half an hour xD)
SC:
Code:
int main()
{
using namespace std;
int num, num2;
cout << "Enter the number you want to square: ";
cin >> num;
cout << "Really? O.o you dont have the brain to square it yourself? fine than... press any key to see the answer." << endl;
system("pause");
num2 = num * num;
cout << " Here you go you lazy monkey: ";
cout << num;
cout << "*";
cout << num;
cout << "= ";
cout << num2 << endl;
system("pause");
return 0;
}
Screenshot:
Thats what happened when you first entered number and than pressed any key.

Vscan: http://vscan.novirusthanks.org/analy...1YXJlci1leGU=/

Attachment below nvm, the computer im on right now doesnt have winrar so i cant make it a .rar file. will post when i get home.

btw a quick question, how can i make it so lets say he types in 10cm2 and it doesnt return any errors?
my First program was :

Code:
#include <iostream>

using namespace std;

int main()
{
cout<<"lol\n";
cin.get();
}
Quote Originally Posted by proman98 View Post
my First program was :

Code:
#include <iostream>

using namespace std;

int main()
{
cout<<"lol\n";
sin.get();
}
This obviously did not compile
Quote Originally Posted by Auxilium View Post


This obviously did not compile
it's a secret. Shush
Quote Originally Posted by 'Bruno View Post
it's a secret. Shush
lol, btw is there a way to remove e+ from really big numbers from the answer if your doing something like 1 km2 = 1000000mm2 but i want to make 1000km = 10000........ but when i do that it gives me 1e+0000
Good Job but i would of added a Check for mynumber before saying it was to big...
if ( mynumber < 50 )
cout << "Blah Blah Blah";
lol misspelling srry
Quote Originally Posted by proman98 View Post
lol misspelling srry
Apology not accepted!!
O.o whit thx your the only one that has helped, i will get to if statements in 9 tutorials. Lol other ppl talking here are trying to hijack the thread.
Posts 1–15 of 32 · Page 1 of 3

Post a Reply

Tags for this Thread

None

Talk with us