Hey guys, this is my second post. I am programming a simple K value calculator.
What would be the most essential way to clear the terminal and start the program all over again? Thankful for any answers!
My code:
#include <iostream>
#include <cmath>
using namespace std;
cout << "The first coordinate pair is: (" << firstX << "," << firstY << ")" << endl;
cout << "The second coordinate pair is: (" << secondX << "," << secondY << ")" << endl;
cout << " " << endl;
cout << "I will calculate the value of K with the following formula: ";
cout << secondY << " - " << firstY << " / " << secondX << " - " << firstX << endl;
cout << "" << endl;
cout << "The value of K is: " << kVal << endl;
cout << "Would you like to know what the value of M is? Type Y or N" << endl;
cin >> userInput;
cout << " " << endl;
if (userInput == "y") {
cout << "I will try to solve the following equation: ";
cout << firstY << " = " << kVal << " * " << firstX << " + M" << endl;
cout << "" << endl;
Suggestion: Move your code to a function, then put your loop in main().
1 2 3 4
while (true)
{ calculate_k_value ();
// clear screen by whatever method
}
PLEASE USE CODE TAGS (the <> formatting button) when posting code. http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.
Put your code in a Do-while-loop and all will be good :)
Ive made 2 changes. I just added this - if (userInput == "y" || userInput == "Y")
And the same with the "n". You know, incase the user types Y instead of y. because the program asks the user to write an uppercase Y so this made more sense.