|
-
Sep 24th, 2001, 10:32 PM
#1
Thread Starter
New Member
My first program! Is it correct? My school's c++ software is still being configured.
Here it is...
#include <iostream.h>
int main ()
{
int n1, n2
cout<<"Enter the number:";
cin>>n1;
cout<<"Enter the second number:";
cin>>n2;
// sum
int sum
sum=n1+n2;
//product
int product
product = n1 * n2;
//differance
int differance
differance = n1\n2;
//output
cout<< "The sum of these numbers are:";
cout<< sum;
cout<< "The diff of these numbers are:";
cout<< differance;
cout<< "The product of these numbers are:";
cout<< product;
return 0;
}
So how wrong is my program? My school sucks so much that I have to write my programs on a friggen piece of paper.
-
Sep 24th, 2001, 10:57 PM
#2
Hyperactive Member
it looks good, except you forgot the ; after variable declarations
Amon Ra
The Power of Learning.
-
Sep 25th, 2001, 06:24 AM
#3
Frenzied Member
It is OK, but maybe for school the main function should be
Code:
main( int argc, char *argv[ ], char *envp[ ] )
{
program-statements
}
-
Sep 25th, 2001, 07:40 AM
#4
Why do that Vlatko? Very likely, he wont need the command line, and I doubt he will EVER need the environ strings.
Also, you tried doing difference with the vb integer division operator. The statement should (probably) be:
Code:
//quotient
int quotient
quotient = n1/n2;
or...
//quotient
double quotient // most schools like doubles o.O
quotient = double(n1)/n2;
Z.
-
Sep 25th, 2001, 09:55 AM
#5
Vlatko, he probably won't have VC++ at school and envp is Microsoft specific.
warrior, you should also add endl (end line) to your couts, or else it will all be one long line...
Code:
cout<< "The sum of these numbers are:";
cout<< sum << endl;
etc.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 25th, 2001, 10:53 AM
#6
Frenzied Member
Well, i know that it is not likely that he will need the command line in apps like this, but i suggested that beacuse i know teachers must teach everything by the rules and many say that the main function should always be with argv and argc regardless of their need in the current app.
-
Sep 25th, 2001, 11:14 AM
#7
Monday Morning Lunatic
Also, iostream.h is deprecated. Use:
Code:
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
// Statements
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|