soulJAHmon Posted March 22, 2014 Share Posted March 22, 2014 http://www.youtube.com/watch?v=KP9GmIKefL8 Quote Link to comment Share on other sites More sharing options...
LA_Kings_Fan Posted March 22, 2014 Share Posted March 22, 2014 http://www.youtube.com/watch?v=KP9GmIKefL8 1 Quote Link to comment Share on other sites More sharing options...
Leader RedBaird Posted March 22, 2014 Leader Share Posted March 22, 2014 I am not familiar with C or C++, but I can only see loops in the code-sets that used the while statements. Quote Link to comment Share on other sites More sharing options...
Heretic121 Posted March 22, 2014 Author Share Posted March 22, 2014 (edited) Okay here I was going for the loop, but after entering either y or n it closes the program. Hmmph! #include <iostream> int main() { float Num1; float Num2; float Answer; int which_calculation; char again = 'y'; { // here std::cout << "Press 1 to add.\n"; std::cin >> which_calculation; std::cout << "Please enter your first number.\n"; std::cin >> Num1; std::cout << "Please enter your second number.\n"; std::cin >> Num2; } // Here if (which_calculation == 1) { Answer = Num1 + Num2; } std::cout << "The answer is ...\n"; std::cout << Answer << std::endl; if (again == 'y') { std::cout << "again (y/n)?"; std::cin >> again; } } The lines I'm talking about have "// here" after them. I just noticed... where's your "return 0;" line? Edited March 22, 2014 by Heretic121 Quote Link to comment Share on other sites More sharing options...
Midnight Posted March 22, 2014 Share Posted March 22, 2014 No where. It would close one way or another, so I just assumed that it was there. I'll play with this hopefully tomorrow. Busy next couple of weeks. Quote Link to comment Share on other sites More sharing options...
parrot Posted March 22, 2014 Share Posted March 22, 2014 #include <iostream> int main() { int input = 0; int iterator = -1; do { iterator++; std::cout << "Enter a number that's not " << iterator << " please"; std::cout << std::endl; std::cin >> input; if (iterator == 10) { std::cout << std::endl; std::cout << "Wow, you're more patient then I am, you win."; return 0; } }while(input != iterator); std::cout << std::endl; std::cout << "Hey! you weren't supposed to enter " << iterator << "!"; return 0; } Quote Link to comment Share on other sites More sharing options...
rtcwet Posted April 9, 2014 Share Posted April 9, 2014 #include <iostream> using namespace std; class Rectangle{ public: int getArea(); Rectangle(int, int); private: int height; int length; }; Rectangle::Rectangle(int length, int height){ this->length = length; this->height = height; } int Rectangle::getArea(void){ return length * height; } int main(int argc, char* argv[]){ int length; cout << "Enter length: " << endl; cin >> length; int height; cout << "Enter height: " << endl; cin >> height; Rectangle rectangle(length, height); cout << "The area of the rectangle is: " << rectangle.getArea() << endl; return 0; } Quote Link to comment Share on other sites More sharing options...
rtcwet Posted April 10, 2014 Share Posted April 10, 2014 #include <iostream> using namespace std; class A{ public: string displayMsg(void); }; class B: public A{ }; string A::displayMsg(void){ return "A message from class A"; } int main(int argc, char* argv[]){ B b; cout << b.displayMsg() << endl; return 0; } Quote Link to comment Share on other sites More sharing options...
rtcwet Posted April 11, 2014 Share Posted April 11, 2014 One of the most interesting things about OOP is Polymorphism. It allows an object to take on many forms. It's similar to the example above, involving class inheritance. Both C++ and Java implement this technique well. Tell me if you like to know more. I'll post some code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.