Then pause your assignments. Go back to your earlier learning material and figure out how to write a "hello world" program in C++. Do that first, then figure out how to write a C++ program that can read a number from the user and print that same number on screen.Originally Posted by solidusMGS
If you cannot write these two programs, then you absolutely cannot do your assignments, so take a step back and figure out how to write these two programs.
If you can write these two programs, then write another one: a program that reads two numbers from the user, adds the numbers, and prints the result to screen.
If you can write this third program, then you can do your first assignment by reading more numbers and changing the "add" to the mathenatical formula.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
No, your learning material should have a section on data types that explains this.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
And how are we supposed to help if you don't even know what it (ARES) is? Even ignoring that, why do you have a "professor" teaching mathematics that would be more appropriate for an 11 or 12 year old? If you're truly at university level and a professor truly assigned this task then the state of education in whatever country you're in is truly sad. Is your "professor" qualified?
Edit: what I'm saying is that this is not a university level problem. I'm saying that it's the kind of problem that an 11 or 12 year old should be able to solve (I don't know what country you're in so I don't know how your school structure is set up, but it's a problem suitable for early highschool, not university. So, what country are you from? Are "professors" in your country actually qualified?)
Last edited by Hodor; 01-26-2020 at 05:57 AM.
Code for "Hello world"
Code:#include <iostream>using namespace std; int main() { cout << "Hi Taco!"; return 0; }
Add/sub number code
For the second one, why can't I put double for int? I am using codeblocks...Code:#include <iostream>using namespace std; int main() { int firstNumber, secondNumber, sumOfTwoNumbers; cout << "Enter two integers: "; cin >> firstNumber >> secondNumber; sumOfTwoNumbers = firstNumber + secondNumber; // Prints sum cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers; return 0; }
Also, where would I put the equation to make it work?
Last edited by solidusMGS; 01-28-2020 at 10:04 AM.
Nothing wrong with that.
Changing int to double is trivial.Code:$ cat foo.cpp && g++ foo.cpp #include <iostream> using namespace std; int main() { int firstNumber, secondNumber, sumOfTwoNumbers; cout << "Enter two integers: "; cin >> firstNumber >> secondNumber; sumOfTwoNumbers = firstNumber + secondNumber; // Prints sum cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers << endl; return 0; } $ ./a.out Enter two integers: 22 33 22 + 33 = 55
Code:$ cat foo.cpp && g++ foo.cpp #include <iostream> using namespace std; int main() { double firstNumber, secondNumber, sumOfTwoNumbers; cout << "Enter two integers: "; cin >> firstNumber >> secondNumber; sumOfTwoNumbers = firstNumber + secondNumber; // Prints sum cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers << endl; return 0; } $ ./a.out Enter two integers: 22 33 22 + 33 = 55 $ ./a.out Enter two integers: 22.22 33.33 22.22 + 33.33 = 55.55
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.