My very first advanced program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
int main ()
{
 system("color 3f");
 unsigned long choice1;
 unsigned long choice2;
 unsigned long result;
 
 cout << "-----------------------------\n";
 cout << "|    + calculator           |\n";
 cout << "|  enter number             |\n";
 cout << "|  enter number 2           |\n";
 cout << "|  bugs included            |\n";
 cout << "|  demo version             |\n";
 cout << "-----------------------------\n";
 cin >> choice1;
 cin >> choice2;
 
 result = choice2 + choice1;
 
cout << "result: " << result << "\n";

cout << "ending program . . .\n";
return 0;

}


what do you think guys ^^
Last edited on
I would use the term advance loosely. Given that it's a simple program with no functions or OO code, it's not really advanced by C++ standards.

Here's a question; what if I enter the word "foo" when asked for a number?

Always make your software idiot-proof. :-)
it says it has bugs, and if you type foo it would type random numbers. im working on fixing the bugs, and BTW im using quincy 2005. is that a good editor?
Last edited on
> unsigned long choice1;

Use the type int for integers, unless you can state a specific reason as to why it should not be int.


1
2
> cin >> choice1;
> cin >> choice2;


Prompt the user for input, perhaps?
1
2
std::cout << "first number: " ; std::cin >> choice1 ;
std::cout << "second number: " ; std::cin >> choice2 ;



> system("color 3f");

Requires #include <cstdlib>
And you do realize that this is not a portable construct, don't you?

Other than that, for a first program, it is just dandy.
> unsigned long choice1;

Use the type int for integers, unless you can state a specific reason as to why it should not be int.


1
2
> cin >> choice1;
> cin >> choice2;


Prompt the user for input, perhaps?
1
2
std::cout << "first number: " ; std::cin >> choice1 ;
std::cout << "second number: " ; std::cin >> choice2 ;



> system("color 3f");

Requires #include <cstdlib>
And you do realize that this is not a portable construct, don't you?

Other than that, for a first program, it is just dandy.


what does #include <cstdlib> do for this program and the std::cout << "first number: and so on

and if you think the system ("color 3f"); doesnt work, you didnt run it
Last edited on
> if you type foo it would type random numbers.

Don't bother about that while writing your first program.
Right now, just expect the user to type in two integers for input.


> im using quincy 2005. is that a good editor?

If you feel comfortable about using it, it is a good editor for you.
does int numbers allow more than 4 billion ?
ProgramProgrammer wrote:
does int numbers allow more than 4 billion ?


No, but it'll allow negative numbers.

http://www.cplusplus.com/doc/tutorial/variables/

If you want a ridiculous range, you can use a long long. I suspect it might be overkill, though.
oh well that all for now
int usually allows just a little over 2 billion, but you should focus on relevant numbers for your calculator. If you have something specific you want to do with a program use long or long long. Congrats with a nice little program there. My first programs didn't have that cool output. You should make sure to include some cool interface/output to make it interesting. :)
> what does #include <cstdlib> do for this program

A name must be declared before it can be used. <cstdlib> is a header file, just as <iostream> is another header file. The header <cstdlib> has the declaration for the function std::system() just as <iostream> has the declaration for std::cout

So, if you want to use std::cout, #include <iostream>
If you want to use std::system(), #include <cstdlib>


> and if you think the system ("color 3f"); doesnt work, you didnt run it

I didn't say it wouldn't work on a particular machine. I just pointed out that it may not work on every machine.
i got another problem now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

int main ()

{
 system("color 3f");
 
 int Price;
 int Tax;
 int Total;
 
 #define Tax 0.06
 
 cout << "------------------------------------\n";
 cout << "|          Price Check             |\n";
 cout << "|        Enter Item Price          |\n";
 cout << "|                                  |\n";
 cout << "|        ----------------          |\n";
 cout << "|        |  {with tax}  |          |\n";
 cout << "|        |    price     |          |\n";
 cout << "|        ----------------          |\n";
 cout << "|                                  |\n";
 cout << "|                                  |\n";
 cout << "------------------------------------\n";
 cin << Price;
 
 cout << " We will get your price in a second.";
 
 Total = Price + Tax;
 
 cout << "Your total is " << Total << " With taxes.";
 
 return 0;
 
}


nvm fixed it
Last edited on
Line 26.
I believe line 13 may also require a semi colon; in future post the error logs also, it does help...
Last edited on
Topic archived. No new replies allowed.