I was wanting to write a program to write a note like I would be typing it normally instead of just all popping up at once. I was wondering how I would go about making it type it out and not a pop up?
Eg:
1 2 3 4 5 6 7 8 9
//note
#include <iostream>
usingnamespace std;
int main();{
cout << "Hello, /n how was your day today? Mine was ok enough to call a great day. /n ... etc
}
excuse my syntax I have not checked it for errors ... I am just asking how to make it type instead of print the cout part..?
The hint I could give without sitting down and coding it right now is that you could us a do while loop to output one letter at a time with a timers in the while to pause for a certain period of time between each char. You could store your message in a std::string.
I am a self taught learning C++ machine ... but needless to say I do remember using loops in python but have not learned yet in C++.
Therefore your advice does not even yield a thought as to how to start this. This is not a project for grade, just a simple question that needs some examples in code please... I am not in a rush as I am not timed/graded so I will wait with excitement over this small amount of knowledge haha
EDIT: sry I mean to compile that paragraph before posting here is the result:
// RPG Typewriter.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <windows.h>
usingnamespace std;
/********************************************
* Introduction *
* Hello there, and welcome to my *
* type writer class for c++. I made this *
* to provide the user a simple solution *
* for creating messages that are displayed *
* like ones in an RPG. You can use this in *
* ANY of your projects royalty free! And, *
* you don't need to credit me... but it *
* would be nice of course. At least tell *
* me if you decide to use it so that I see *
* it at work in your game/project =D *
* *
* How to use *
* You can create a message in three simple *
* steps. First, you must declare a type *
* writer object. Next, use *
* setmessage(), to initiate your type *
* writer's message. Once that's done, use *
* write() to display your message. Note: *
* in the write() function, there is a *
* parameter called speed which stands for *
* the number of characters displayed per *
* second. Well, that's it. I hope you *
* enjoy! ;) *
* *
* SuperSonic *
********************************************/
struct typewriter
{
public:
char message[256];
void setmessage(char input[256])
{
counter = 0;
messagedone = false;
for(int i = 0; i < 256; i++)
{
message[i] = input[i];
}
}
void write(int speed)
{
while(!messagedone)
{
if(message[counter])
{
if (message[counter] != ' ')
Beep(800,100);
cout << message[counter];
counter++;
}
else
{
messagedone = true;
}
Sleep(1000/speed);
}
}
private:
int counter;
bool messagedone;
} Write;
int main()
{
Write.setmessage("Hello world.\nDo you like the type-writer effect?\nThis can be used in any program.");
Write.write(10);
Sleep(2000);
Write.setmessage("\n\nThank you for viewing, and trying out, my program!!");
Write.write(30);
Sleep(2000);
Write.setmessage("\n\nGood-bye\n\n\t");
Write.write(30);
return 0;
}