hello, i have learned all the basics and some more advanced stuff...what do i do next...i know for some of you c++ is your job...do you make apps or games.....do u use win32??? -thx
well i would like to make a calculator using graphics....heres a program that sums up all i know pretty much exept pointers....the other thing i would like to know before graphics is how in a calculator program can i make it let the user use more than one operation in a math problem
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int Total = 0;
int Amount;
int Number;
int whatoperation;
int answertoaverage;
int restart;
while (restart) {
system("CLS");
cout << "Here are your choices(enter the number before the operation)" << endl << endl;
cout << "1.Addition" << endl;
cout << "2.Subtraction" << endl;
cout << "3.Multiplication" << endl;
cout << "4.Division" << endl;
cout << "5.Average Calculator" << endl;
cin >> whatoperation;
system("CLS");
switch(whatoperation){
case 1:
cout << "Enter in how many numbers you want to use" << endl;
cin >> Amount;
for(int i = 0; i < Amount; i++) // Keeps looping until i == Amount
{
cout << "Number " << i << ": " ; // Shows user what number they are entering
cin >> Number;
Total = Number + Total; // Adds number to total
}
cout << "The total is " << Total << endl; // Prints out total value when loop has finished
break;
case 2:
cout << "Enter in how many numbers you want to use" << endl;
cin >> Amount;
for(int i = 0; i < Amount; i++)
{
cout << "Number " << i << ": " ;
cin >> Number;
if(i == 0)
{
Total = Total + Number;
}
else
{
Total = Total - Number;
}
}
cout << "The total is " << Total << endl;
break;
case 3:
cout << "Enter in how many numbers you want to use" << endl;
cin >> Amount;
for(int i = 0; i < Amount; i++)
{
cout << "Number " << i << ": " ;
cin >> Number;
if(i == 0)
{
Total = Total + Number;
}
else
{
Total = Total * Number;
}
}
cout << "The total is " << Total << endl;
break;
case 4:
cout << "Enter in how many numbers you want to use" << endl;
cin >> Amount;
for(int i = 0; i < Amount; i++)
{
cout << "Number " << i << ": " ;
cin >> Number;
if(i == 0)
{
Total = Total + Number;
}
else
{
Total = Total / Number;
}
cout << "The total is " << Total << endl;
}
break;
case 5:
cout << "Enter how many numbers you want to find the average of: ";
cin >> Amount;
for(int i = 0; i < Amount; i++)
{
cout << "Number " << i << ": " ;
cin >> Number;
Total = Number + Total;
}
answertoaverage = Total / Amount;
cout << "The average of those " << Amount << " numbers is " << answertoaverage << endl;
}
cout << "enter 1 to restart or 2 to quit: ";
cin >> restart;
if(restart == 1){
}else{
break;
}
}
cin.get();
return 0;
}
For your second question, you'd have to write some sort of simple parser. That could be rather tricky and it would require you to be very familiar with the std::string class, but it's fun to see it work.
I'd suggest looking into Qt to create GUI applications. It might be a little bit intimidating at first as it is a very different world, but ultimately it's not that hard at all. Hey, maybe it's even easier. :)
Okay, I take that back. If that program really showcases *all* you know, then I don't think you're quite ready for GUI programming in C++ yet. Sorry. :(
Knowing how to use classes (including constructors/destructors) is an absolute prerequisite for using Qt. It is similarly be a prerequisite for using wxWidgets or gtkmm, which are two other major C++ GUI libraries. After that, though, you might be ready, though I'd suggest learning about inheritance and polymorphism as well.
You have a decent grasp on the basics, and I'm currently reading a book (Professional C++ 2nd Edition) that skips completely over those basics, except for a very cursory review of them in the first chapter, and then moves directly into how to design programs, and starts the code off with classes and flows from there. It includes a lot of advanced applications, as well as a thorough review of containers & algorithms, classes, inheritance, polymorphism, advanced string handling, etc.
...and even that's just barely scratching the surface of this resource. I would estimate that you've reached the approximate point where this could be an appropriate investment for you. You can get it from www.wrox.com
EDIT:
P.S.
The book also goes over what will happen and how to prevent it when your users (and they WILL) put in a non-int when you're expecting to see an int. Exceptions, ZING!