Hello,
I recently finished a tutorial on C++ and I have written a small program. Could you please take a look at my code and give me feedback on it?
It's a program that will ask you for two values and then add them together.
Please be nice, since it's my first "non-tutorial" program and I just turned 13.
/*
* My first program that wasn't from a tutorial.
* (C) 2007 Laseredd.
*/
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Calc
{
int num1, num2;
public:
void set_num(int, int);
int add();
};
void Calc::set_num(int a, int b)
{
num1 = a;
num2 = b;
}
int Calc::add()
{
return (num1 + num2);
}
int main()
{
Calc calc;
string valid;
int numb1, numb2;
cout << "What numbers to you want to add? " << endl;
cout << "Number 1: ";
getline(cin, valid);
stringstream(valid) >> numb1;
cout << "Number 2: ";
getline(cin, valid);
stringstream(valid) >> numb2;
calc.set_num(numb1, numb2);
cout << calc.add();
return 0;
}