QuestionHelpSimple-Calculator (C++)

Posts 1–9 of 9 · Page 1 of 1
Simple-Calculator (C++)
This is a silly question but one I thought I'd ask.
I've grown a habit to have my text to appear to be typed out to the user; so that not just a lot of information is thrown at them.
I was wondering if there was a better way in doing it than what I did here :


Code:
#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

class Information
{

public:

	void informationalText()
	{

		cout << "B";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "s";
		Sleep(85);
		cout << "i";
		Sleep(85);
		cout << "c";
		Sleep(85);
		
		cout << " ";
		Sleep(85);

		cout << "C";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "l";
		Sleep(85);
		cout << "c";
		Sleep(85);
		cout << "u";
		Sleep(85);
		cout << "l";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "t";
		Sleep(85);
		cout << "o";
		Sleep(85);
		cout << "r";
		Sleep(85);

		cout << " ";
		Sleep(85);

		cout << "B";
		Sleep(85);
		cout << "y";
		Sleep(85);
		cout << ":";
		Sleep(85);

		cout << " ";
		Sleep(85);

		cout << "S";
		Sleep(85);
		cout << "p";
		Sleep(85);
		cout << "l";
		Sleep(85);
		cout << "i";
		Sleep(85);
		cout << "t";
		Sleep(85);
		cout << "z";
		Sleep(85);
		cout << "o";
		Sleep(85);
		cout << "B";
		Sleep(85);
		cout << "e";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "r\n\n";
		



	}


	void saying1()
	{

		cout << "Please Enter three values I will calculate them into a sum! \n\n";
	}


	void saying2()
	{

		cout << "P";
		Sleep(85);
		cout << "l";
		Sleep(85);
		cout << "e";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "s";
		Sleep(85);
		cout << "e";
		Sleep(85);
		
		cout << " ";
		Sleep(85);
		
		cout << "e";
		Sleep(85);
		cout << "n";
		Sleep(85);
		cout << "t";
		Sleep(85);
		cout << "e";
		Sleep(85);
		cout << "r";
		Sleep(85);

		cout << " ";
		Sleep(85);

		cout << "a";
		Sleep(85);

		cout << " ";
		Sleep(85);

		cout << "v";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "l";
		Sleep(85);
		cout << "u";
		Sleep(85);
		cout << "e";
		Sleep(85);
		cout << " ";
		Sleep(85);
		cout << " ";
		Sleep(85);
	}


	void saying3()
	{


		cout << "E";
		Sleep(85);
		cout << "n";
		Sleep(85);
		cout << "t";
		Sleep(85);
		cout << "e";
		Sleep(85);
		cout << "r";
		Sleep(85);
		
		cout << " ";
		Sleep(85);
		
		cout << "t";
		Sleep(85);
		cout << "h";
		Sleep(85);
		cout << "e";
		Sleep(85);

		cout << " ";
		Sleep(85);

		cout << "l";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "s";
		Sleep(85);
		cout << "t";
		Sleep(85);


		cout << " ";
		Sleep(85);

		cout << "v";
		Sleep(85);
		cout << "a";
		Sleep(85);
		cout << "l";
		Sleep(85);
		cout << "u";
		Sleep(85);
		cout << "e";
		Sleep(85);
		cout << " ";
		Sleep(85);
		cout << " ";

	}

	void finalSaying()
	{

		cout << "The calculation of thoose numbers entered is ";
	}
};



int main()
{

	int x;
	int y;
	int z;
	int sum;
	
	
	
	
	
	Information io;
	




	io.informationalText();
	Sleep(1500);

	io.saying1();
	Sleep(1500);

	io.saying2();
	cin >> x;
	Sleep(350);

	io.saying2();
	cin >> y;
	Sleep(350);

	io.saying3();
	cin >> z;
	cout << " \n\n";


	sum = x + y + z;

	io.finalSaying(); cout << sum;

	





	


	
	Sleep(5000);

	return 0;
}
Make a function that takes in a string and make a loop that loops through it and adds the sleep?

EDIT: Feeling nice today
Code:
void sleepMessageThingEveryoneLovesLongFunctionNamesxD(const char* string, int sleeptime) {
    for(int i = 0;i<strlen(string);i++) {
        std::cout << string[i];
        Sleep(sleeptime);
    }
    std::cout << std::endl;
}
Yeah I'm new to coding actually I just started like a few hours ago. I will keep this in mind however; thanks !
Quote Originally Posted by Splitzo View Post
Yeah I'm new to coding actually I just started like a few hours ago. I will keep this in mind however; thanks !
Welcome to the most fun and frustrating hobby!
Oh I could only imagine!
I myself have already ran into some rather annoying mistakes & I only just began. ; - ;
Im going to tell you something that will allow you to be a better programmer for the rest of your life, if you are doing something multiple times, you can probably do it in a loop:
Code:
std::string str ("Test string");
  for (unsigned i=0; i<str.length(); ++i)
  {
    std::cout << str.at(i);
    Sleep(85);
  }
Not gonna spoon feed you, you gotta learn it urself dude
First thing in programing is... DRY = Don't repeat yourself (it isn't easy believe me);
Quote Originally Posted by EI%&gasr#$^ View Post
First thing in programing is... DRY = Don't repeat yourself (it isn't easy believe me);
And you are so right. I find my self doing shit when I can do a loop instead lol.
For better practices, start using flush and/or endl. I know most compilers nowadays automatically solve those issues but it's better to start off with the right approach.

So if you want something to be printed end your cout with flush

Code:
std::cout << "Text" << std::flush;
Sleep(85);
Or without the std if you have are using namespace std...


Quote Originally Posted by romponu View Post
Im going to tell you something that will allow you to be a better programmer for the rest of your life, if you are doing something multiple times, you can probably do it in a loop:
Code:
std::string str ("Test string");
  for (unsigned i=0; i<str.length(); ++i)
  {
    std::cout << str.at(i);
    Sleep(85);
  }
Not gonna spoon feed you, you gotta learn it urself dude
Or use the new for range feature.

Code:
using namespace std;

int main()
{
	string str = "This is a test string";

	for (char c : str) {
		cout << c << flush;
		Sleep(85);
	}

	return 0;
}
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us