04.03.2014, 18:21
I think you mean a program like this:
Here is an example on how to use it:
I'vent put more comments for explanation, so I hope you understand the rest yourself. If you have any other problem in C++, then don't forget to leave me a message..
PHP код:
//Author : Zayan Imran <0bzayan@gmail.com>
//Purpose : Write a message to a line.
#include "stdafx.h" //Use this only if you are running this on Visual C++
#include "iostream" //This provides some things for use, like: cout, cin, etc..
#include <string>
using namespace std; //This is not useful, but it will remove a headace.
//-By using this, you wont have to add "std::" to cout.
//-If this isn't used, you'll have to add "std::" to cout when you use cout. std::cout << "Hello\n";
int main()
{
int gLine = 0, //An variable, which can hold numbers only.
loop = 1,
hasputerror = 0;
string option; //Get what the user typed his options.
while(loop == 1)
{
cout << "Hello - Please choose the line's number on which you want to write on: "; //TIP: Usage of cout: cout << "Something"; "\n" is newline, endl as a token be also used.
cin >> gLine; //Wait until the user has entered the number, and store it in "gLine".
int hasputerror = 0;
if(gLine < 1 || gLine > 4) //Check if the user has entered the line's number greater than 4, or less than 1.
{
cout << "Error: The number can only range from 1-4.\nType \"tryagain\" to restart, OR, type \"exit\" to exit the program.\n"; //Display an errer if so. And give 2 options.
hasputerror = 1;
}
else //If the user has done things correct, then:
{
string line;
int i = 0;
cout << "Write your line's message: ";
cin >> line;
if(gLine == 1)
{
cout << "1. " << line << "\n";
cout << "2. \n";
cout << "3. \n";
cout << "4. \n";
}
else if(gLine == 2)
{
cout << "1. \n";
cout << "2. " << line << "\n";
cout << "3. \n";
cout << "4. \n";
}
else if(gLine == 3)
{
cout << "1. \n";
cout << "2. \n";
cout << "3. " << line << "\n";
cout << "4. \n";
}
else if(gLine == 4)
{
cout << "1. \n";
cout << "2. \n";
cout << "3. \n";
cout << "4. " << line << "\n";
}
system("PAUSE"); //Wait
exit(1); //Exit
}
if(hasputerror == 1)
{
cin >> option;
if(option == "exit")
{
system("PAUSE");
hasputerror = 0;
}
else if(option == "tryagain")
{
cout << "[-]\n[-]\n[-]\n";
hasputerror = 0;
main();
}
}
}
}
Код:
Hello - Please choose the line's number on which you want to write on: 2 Write your line's message: Hello 1. EMPTY STRING 2. Hello 3. EMPTY STRING 4. EMPTY STRING