Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-13-2007, 05:41 PM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Question Baffled

I could use some help once again. I've written a program which ought to write an HTML file with user-specified features.
The problem is not that it doesn't compile, but that it gives a "The system cannot find the file specified.". When I try to get through the program I get as far as "Write to webpage? [Y/N] : ", before the program exits on my input.
I know it is a lot to ask but if anyone can advise me on what I can do to fix this I would be very greatful.
Thanks in advance if anyone has the time.
Here's the code :

Code:
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>

using namespace std;

string title, bgcolor, img, imgyn, imgpos, textface, write, again, dalign, alt, txtalign, face, newl, fontcol, para, open;
int size, fontch, fcol, align, back, txal, ipos, l;

int main() {
    system("title <HTML> Writer");
    srand(time (0));
    cout<<endl;
    cout<<"<HTML> Writer!"<<endl;
    cout<<"Welcome."<<endl;
    cout<<endl;
    cout<<"Please remember that when you save a file in <HTML> Writer it overwrites the last one with the same name."<<endl;
    cout<<"If you have a previous webpage with the same name that you want to keep, please copy or rename it to preserve it."<<endl;
    cout<<"When you are ready please hit [Enter] to continue...";
    cin.get();
    system("cls");
    cout<<endl;
    cout<<"Write to webpage? [Y/N] : ";
    cin>> write;
    if (write == "Y" || write == "y") { }
    else {
         cout<<"You have decided not to modify htmlwriter.htm at this time."<<endl;
         cout<<"Hit [Enter] to exit...";
         cin.get();
         return 0;
         }
    int quit=0;
    while (quit != 1) {
        ofstream myFile("htmlwriter.htm");
        myFile<<"<html>"<<endl;
        myFile<<"<!--Written using <HTML> Writer 1.0-->"<<endl;
        cout<<"File created."<<endl;
        myFile<<"<head>"<<endl;
        cout<<endl;
        cout<<"What would you like as a title for your page? : ";
        cin>> title;
        myFile<<"<title>"<<title<<"</title>"<<endl;
        cout<<"Title entered."<<endl;
        system("cls");
        myFile<<"</head>"<<endl;
        cout<<endl;
        cout<<"What colour would you like your file's background colour to be? : ";
        cout<<endl;
        cout<<"[1] White"<<endl;
        cout<<"[2] Black"<<endl;
        cout<<"[3] Green"<<endl;
        cout<<"[4] Red"<<endl;
        cout<<"[5] Blue"<<endl;
        cout<<"[6] Yellow"<<endl;
        cout<<endl;
        cout<<"[7] Advanced settings"<<endl;
        cout<<"[0] Randomise"<<endl;
        cout<<endl;
        cout<<"Your choice -"<<endl;
        cout<<"[1/2/3/4/5/6/7/0] : ";
        cin>> back;
        if (back == 1) {
                 (bgcolor = "white");
                 }
        else if (back == 2) {
             (bgcolor = "black");
                 }
        else if (back == 3) {
             (bgcolor = "green");
                 }
        else if (back == 4) {
             (bgcolor = "red");
             }
        else if (back == 5) {
             (bgcolor = "blue");
             }
        else if (back == 6) {
             (bgcolor = "yellow");
             }
        else if (back == 7) {
             cout<<"Advanced background settings"<<endl;
             cout<<endl;
             cout<<"[8] Specify a different colour"<<endl;
             cout<<"[9] Use a background image"<<endl;
             cout<<endl;
             cout<<"Your choice [1/2] : ";
             cin>> back;
             if (back == 8) {
                      cout<<"Background colour : ";
                      cin>> bgcolor;
                      }
             else if (back == 9) {
                  cout<<"You have chosen to use an image as your file's background."<<endl;
                  cout<<"Please enter the full address of the file"<<endl;
                  cout<<"If you are using an image from the internet please put the entire address (including http://)"<<endl;
                  cout<<"If you are using one stored on your computer please copy the image to the same directory (folder) as htmlwriter.htm."<<endl;
                  cout<<"Then simply put the entire file name (not address, just the name)"<<endl;
                  cout<<"Remember to include the file extension. This can be seen with extension viewing enabled or on the file's properties."<<endl;
                  cout<<endl;
                  cout<<"File : ";
                  cin>> bgcolor;
                  }
             else { }
             }
        else if (back == 0) {
             cout<<"Randomising..."<<endl;
             int random = (1 + rand() % 6);
             if (random == 1) {
                        (bgcolor = "white");
                        }
             else if (random == 2) {
                  (bgcolor = "black");
                  }
             else if (random == 3) {
                  (bgcolor = "green");
                  }
             else if (random == 4) {
                  (bgcolor = "red");
                  }
             else if (random == 5) {
                  (bgcolor = "blue");
                  }
             else if (random == 6) {
                  (bgcolor = "yellow");
                  }
             else {
                  cout<<"Error."<<endl;
                  (bgcolor = "white");
                  }
        if (back == 9) {
                 myFile<<"<body background='"<<bgcolor<<"'>"<<endl;
                 }
        else {
             myFile<<"<body bgcolor='"<<bgcolor<<"'>"<<endl;
             }
        cout<<"Background : "<<bgcolor<<""<<endl;
        cout<<"Finished setting background."<<endl;
        cout<<"Hit [Enter] to continue...";
        cin.get();
        system("cls");
        cout<<endl;
        int align;
        cout<<"How would you like to align the page? : "<<endl;
        cout<<endl;
        cout<<"[1] Left [2] Centre [3] Right"<<endl;
        cout<<"Your choice -"<<endl;
        cout<<"[1/2/3] : ";
        cin>> align;
        if (align == 1) {
                  (dalign = "left");
                  }
        else if (align == 2) {
             (dalign = "center");
             }
        else if (align == 3) {
             (dalign = "right");
             }
        else {
             cout<<"Error."<<endl;
             (dalign = "center");
             }
        myFile<<"<div align='"<<dalign<<"'>"<<endl;
        cout<<"Content alignment : "<<dalign<<""<<endl;
        cout<<"Finished alignment settings."<<endl;
        cout<<"Hit [Enter] to continue...";
        cin.get();
        cout<<"Would you like to insert an image into your page? [Y/N] : ";
        cin>> imgyn;
        if (imgyn == "y" || imgyn == "Y") {
                  cout<<"If the file is hosted on the internet, please enter the entire address."<<endl;
                  cout<<"If it is stored on your computer, please copy it to the same directory (folder) as htmlwriter.htm."<<endl;
                  cout<<"Then simply put the name (not entire address, just the file name will suffice)"<<endl;
                  cout<<"Remember to include the file extension. This can be viewed with extension viewing enabled or in the file's properties."<<endl;
                  cout<<endl;
                  cout<<"File : ";
                  cin>> img;
                  cout<<"Image chosen : "<<img<<""<<endl;
                  cout<<"Alternative text for the image : ";
                  cin>> alt;
                  cout<<"Hit [Enter] to continue...";
                  cin.get();
                  system("cls");
                  cout<<endl;
                  cout<<"Where would you like to position your image? :"<<endl;
                  cout<<endl;
                  cout<<"[1] To the left"<<endl;
                  cout<<"[2] At the top"<<endl;
                  cout<<"[3] To the right"<<endl;
                  cout<<endl;
                  cout<<"Position -"<<endl;
                  cout<<"[1/2/3] : ";
                  cin>> ipos;
                  myFile<<"<table border='0' cellpadding='0' cellspacing='2'>"<<endl;
                  if (ipos == 1) {
                           myFile<<"<tr>"<<endl;
                           myFile<<"<td>"<<endl;
                           myFile<<"<div align='center'>"<<endl;
                           myFile<<"<img src='"<<img<<"' alt='"<<alt<<"'>"<<endl;
                           myFile<<"</div>"<<endl;
                           myFile<<"</td">
                           myFile<<"<td valign='top'>"<<endl;
                           cout<<"Image inserted."<<endl;
                           }
                  else if (ipos == 2) {
                       myFile<<"<tr>"<<endl;
                       myFile<<"<td valign='top'>"<<endl;
                       myFile<<"<div align='center'>"<<endl;
                       myFile<<"<img src='"<<img<<"' alt='"<<alt<<"'>"<<endl;
                       myFile<<"<p>";
                       myFile<<"</div>"<<endl;
                       cout<<"Image inserted."<<endl;
                       }
                  else if (ipos == 3) {
                       cout<<"The image will be inserted later."<<endl;
                       }
                  else {
                       cout<<"Error."<<endl;
                       (ipos = 1);
                       myFile<<"<tr>"<<endl;
                       myFile<<"<td>"<<endl;
                       myFile<<"<div align='center'>"<<endl;
                       myFile<<"<img src='"<<img<<"' alt='"<<alt<<"'>"<<endl;
                       myFile<<"</div>"<<endl;
                       myFile<<"</td>"<<endl;
                       myFile<<"<td valign='top'>"<<endl;
                       cout<<"Image inserted to the left."<<endl;
                       }
                  }
        else {
             cout<<"No image was used."<<endl;
             }
        cout<<"Hit [Enter] to continue...";
        cin.get();
        system("cls");
        cout<<endl;
        cout<<"Time to configure text settings."<<endl;
        cout<<endl;
        cout<<"How would you like to align your text? :"<<endl;
        cout<<endl;
        cout<<"[1] Left [2] Centre [3] Right"<<endl;
        cout<<"[1/2/3] : ";
        cin>> txal;
        if (txal == 1) {
                 (txtalign = "left");
                 }
        else if (txal == 1) {
             (txtalign = "center");
             }
        else if (txal == 3) {
             (txtalign = "right");
             }
        else {
             cout<<"Error."<<endl;
             (txtalign = "left");
             cout<<"Alignment set to : left"<<endl;
             }
        if (imgyn != "y" && imgyn != "Y") {
                  myFile<<"<table border='0' cellpadding='0' cellspacing='2'>"<<endl;
                  myFile<<"<tr>"<<endl;
                  myFile<<"<td valign='top'>"<<endl;
                  myFile<<"<div align='"<<txtalign<<"'>"<<endl;
                  }
        else if (ipos == 1) {
             myFile<<"<div align='"<<txtalign<<"'>"<<endl;
             }
        else if (ipos == 2) {
             myFile<<"<div align='"<<txtalign<<"'>"<<endl;
             }
        else if (ipos == 3) {
             myFile<<"<tr>"<<endl;
             myFile<<"<td valign='top'>"<<endl;
             myFile<<"<div align='"<<txtalign<<"'>"<<endl;
             }
        system("cls");
        cout<<endl;
        cout<<"What font would you like to use on your page? : "<<endl;
        cout<<endl;
        cout<<"[1] Arial"<<endl;
        cout<<"[2] Times New Roman"<<endl;
        cout<<"[3] Comic Sans MS"<<endl;
        cout<<"[4] Lucida Calligraphy"<<endl;
        cout<<endl;
        cout<<"[5] Advanced settings"<<endl;
        cout<<endl;
        cout<<"Font : ";
        cin>> fontch;
        if (fontch == 1) {
                   (face = "Arial");
                   }
        else if (fontch == 2) {
             (face = "Times New Roman");
             }
        else if (fontch == 3) {
             (face = "Comic Sans MS");
             }
        else if (fontch == 4) {
             (face == "Lucida Calligraphy");
             }
        else if (fontch == 5) {
             cout<<"Advanced font face settings."<<endl;
             cout<<endl;
             cout<<"Enter font name : ";
             cin>> face;
             }
        else {
             cout<<"Error."<<endl;
             (face = "Arial");
             cout<<"Font face set to : Arial"<<endl;
             }
        system("cls");
        cout<<endl;
        cout<<"What colour would you like the text to be?"<<endl;
        cout<<"Note : Background is "<<bgcolor<<""<<endl;
        cout<<endl;
        cout<<"[1] Black"<<endl;
        cout<<"[2] White"<<endl;
        cout<<"[3] Green"<<endl;
        cout<<"[4] Red"<<endl;
        cout<<"[5] Blue"<<endl;
        cout<<"[6] Yellow"<<endl;
        cout<<endl;
        cout<<"[7] Advanced"<<endl;
        cout<<"[0] Randomise"<<endl;
        cout<<endl;
        cout<<"Font colour : ";
        cin>> fcol;
        if (fcol == 1) {
                 (fontcol = "black");
                 }
        else if (fcol == 2) {
             (fontcol = "white");
             }
        else if (fcol == 3) {
             (fontcol = "green");
             }
        else if (fcol == 4) {
             (fontcol = "red");
             }
        else if (fcol == 5) {
             (fontcol = "blue");
             }
        else if (fcol == 6) {
             (fontcol = "yellow");
             }
        else if (fcol == 7) {
             cout<<"Advanced font colour settings."<<endl;
             cout<<endl;
             cout<<"Font colour : ";
             cin>> fontcol;
             }
        else if (fcol == 0) {
             cout<<"Randomising..."<<endl;
             int rancol;
             (fontcol = bgcolor);
             while (fontcol == bgcolor) {
                   (rancol = 1 + rand() % 6);
                   if (rancol == 1) {
                              (fontcol = "black");
                              }
                   else if (rancol == 2) {
                        (fontcol = "white");
                        }
                   else if (rancol == 3) {
                        (fontcol = "green");
                        }
                   else if (rancol == 4) {
                        (fontcol = "red");
                        }
                   else if (rancol == 5) {
                        (fontcol = "blue");
                        }
                   else if (rancol == 6) {
                        (fontcol = "yellow");
                        }
                   else {
                        cout<<"Error."<<endl;
                        (fontcol = "black");
                        }
                   }
             }
        cout<<"Font colour set to : "<<fontcol<<""<<endl;
        cout<<"Hit [Enter] to continue...";
        cin.get();
        system("cls");
        myFile<<"<font color='"<<fontcol<<"'>"<<endl;
        myFile<<"<h1>"<<title<<"</h1>">
        myFile<<"<p>"<<endl;
        cout<<endl;
        cout<<"Time to enter text into your webpage."<<endl;
        cout<<"Enter 'x' as a line entry (without quote marks) at any time to stop writing the text."<<endl;
        (l = 0);
        (para = "");
        while (para != "x") {
            myFile<<" "<<para<<endl;
            l++;
            cout<<"Line "<<l<<" : ";
            cin>> para;
            myFile<<"<br>"<<endl;
            }
        myFile<<"</font>"<<endl;
        cout<<"Writing finished."<<endl;
        if (ipos == 3) {
                 myFile<<"</div>"<<endl;
                 myFile<<"</td>"<<endl;
                 myFile<<"<td>"<<endl;
                 myFile<<"<div align='center'>"<<endl;
                 myFile<<"<img src='"<<img<<"'>"<<endl;
                 myFile<<"</td>"<<endl;
                 myFile<<"</tr>"<<endl;
                 }
        else {
             myFile<<"</div>"<<endl;
             myFile<<"</td>"<<endl;
             myFile<<"</tr>"<<endl;
             }
        myFile<<"</frame>"<<endl;
        myFile<<"</body>"<<endl;
        myFile<<"</html>"<<endl;
        myFile.close();
        cout<<"The page has been completed."<<endl;
        cout<<"Would you like to open your webpage now? [Y/N] : ";
        cin>> open;
        if (open == "y" || open == "Y") {
                 cout<<"Opening htmlwriter.htm..."<<endl;
                 system("htmlwriter.htm");
                 }
        else { }
        system("cls");
        cout<<endl;
        cout<<"Would you like to re-make the webpage? [Y/N] : "<<endl;
        cin>> again;
        if (again == "y" || again == "Y") {
                  (quit=0);
                  system("cls");
                  }
        else {
             (quit = 1);
             }
        }
        }
    system("cls");
    cout<<"Thanks for using <HTML> Writer."<<endl;
    cout<<"Your webpage should be in the same directory (folder) as this program."<<endl;
    cout<<"Hit [Enter] to exit..."<<endl;
    cin.get();
    return 0;
}
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-13-2007, 06:00 PM
Uniqe Uniqe is offline
Newbie
 
Join Date: Jan 2007
Posts: 4
Rep Power: 0
Uniqe is on a distinguished road
Default

If you press 'N' do you see:

You have decided not to modify htmlwriter.htm at this time.

?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-13-2007, 06:35 PM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Default

It does give that I think but only for a split second as it exits the program at that exact moment.
Edit: Oh yeah, when I hit "y" or "Y" it does go so far as to create the file before exiting. The file's source code is blank, however.
__________________

Last edited by shibbythestoner; 09-13-2007 at 06:39 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-13-2007, 08:09 PM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default

**** that is a lot of code. It looks like every time you loop you open the same file:

Code:
    while (quit != 1) {
        ofstream myFile("htmlwriter.htm");
What are you compiling this with and I'll try to replicate?
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-14-2007, 01:08 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Quote:
Originally Posted by shibbythestoner
The system cannot find the file specified.
You've this problem, because of this line.
Code:
system("title <HTML> Writer");
Windows will think you're title shall be "<HTML," because '>' is used for sending the output into a file. So it thinks the title shall be "<HTML" and the output is going to be written in the file "Writer."


I need to go now, but I'll look at the rest of the code later.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 09-14-2007, 12:22 PM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Default

Quote:
Originally Posted by Lop View Post
**** that is a lot of code. It looks like every time you loop you open the same file:

Code:
    while (quit != 1) {
        ofstream myFile("htmlwriter.htm");
What are you compiling this with and I'll try to replicate?
I'm using Dev-C++.

Quote:
Originally Posted by v0id View Post
You've this problem, because of this line.
Code:
system("title <HTML> Writer");
Windows will think you're title shall be "<HTML," because '>' is used for sending the output into a file. So it thinks the title shall be "<HTML" and the output is going to be written in the file "Writer."


I need to go now, but I'll look at the rest of the code later.
This worked, and I now have no file not found error, thanks very much. However, my program still exits.
I've tried taking it out of the loop and got rid of the option whether or not to write but it gets as far as the first occurence of cin.get(); and quits on me again.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-15-2007, 06:33 AM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Default

I've tried making quite a few random changes now but it still goes as far as creating the file then just quits.



In theory it should work...I can't see any mistakes, and it compiles fine...
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-15-2007, 08:45 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

I'm sorry I haven't answered you yet, but I'm on holidays, so I don't have much time to sit on the computer. It means I don't have the time to look your code through right now, but I've some suggestions.

When you're getting input, which you want to compare, let's say single characters, then don't use strings! It's unnecessary, and sometimes it can be hard to compare with them. Like in your code, you want to let the user input 'y'/'Y' or something else. Instead of getting it into a string, use a char or an int.

std::cin and char or int for numbers/single characters,
and std::getline for strings.

Also, to get a better overview of your code, replace many of your if-statements with switch-statements. It will be easier to read then.

Try following my guidelines, if you want to, and then post the new code.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-15-2007, 09:02 AM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Default

Quote:
Originally Posted by v0id View Post
I'm sorry I haven't answered you yet, but I'm on holidays, so I don't have much time to sit on the computer. It means I don't have the time to look your code through right now, but I've some suggestions.

When you're getting input, which you want to compare, let's say single characters, then don't use strings! It's unnecessary, and sometimes it can be hard to compare with them. Like in your code, you want to let the user input 'y'/'Y' or something else. Instead of getting it into a string, use a char or an int.

std::cin and char or int for numbers/single characters,
and std::getline for strings.

Also, to get a better overview of your code, replace many of your if-statements with switch-statements. It will be easier to read then.

Try following my guidelines, if you want to, and then post the new code.
Ok, I hope I didn't seem like I was trying to rush or anything...
So for small things with no spaces I will use char instead of string, sure. I'd say that's a good plan. I'll use getline for strings; I know how to do that and I have the basics of switch statements down (though I am not oft to use them, so it'll be good practice for me anyway).
Thanks for your advice, I'll re-write my code soon.

Edit: I hope the emote in my last post didn't give mixed messages; the problem is on some forums images get put in the wrong place at random sometimes. Probably just Firefox 2 or something, but I simply clicked on the emote I wanted to put without looking at alt text just to make sure. It was meant to be the "???" emote.
__________________

Last edited by shibbythestoner; 09-15-2007 at 09:08 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-15-2007, 01:26 PM
shibbythestoner's Avatar   
shibbythestoner shibbythestoner is offline
Programmer
 
Join Date: Jun 2007
Location: Scotland
Age: 17
Posts: 129
Rep Power: 6
shibbythestoner is on a distinguished road
Default

Thank very much V0id! Your suggestions helped make my program work!
I still have some bugs to fix and perhaps features to add, but this is pretty much it now :

Code:
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>

using namespace std;

string writeyn, title, bgcolour, pagealign, txtalign, fontface, fontcolour, imgsrc, alt, linetxt, imgyn, openyn, againyn;
int bgc, stored, pal, imgpos, txal, fontf, fontc, linenum;

int main() {
    system("title HTML Writer");
    srand(time (0));
    cout<<endl;
    cout<<"<HTML Writer!>"<<endl;
    cout<<"Welcome."<<endl;
    cout<<endl;
    cout<<"Please remember that when you save a file in HTML Writer, it overwrites the last file with the same file name."<<endl;
    cout<<"If you have a previous webpage with the same name that you want to keep, please copy or rename it to preserve it."<<endl;
    cout<<"When you are ready please hit [Enter] to continue..."<<endl;
    cin.get();
    system("cls");
         
    int quit = 0;
    cout<<"Modify file? [Y/N] : ";
    getline(cin, writeyn);
    if (writeyn == "Y" || writeyn == "y") { }
    else {
         return 0;
         }
    while (quit != 1) {
          ofstream myFile("htmlwriter.htm");
          myFile<<"<html>"<<endl;
          myFile<<"<head>"<<endl;
          myFile<<"<title>";
          
          cout<<"File created."<<endl;
          cout<<endl;
          cout<<"What would you like as a title for your page?"<<endl;
          cout<<"Title : ";
          getline (cin, title);
          
          myFile<<title<<"</title>"<<endl;
          myFile<<"</head>"<<endl;
          
          cout<<"Title entered."<<endl;
          cout<<"Hit [Enter] to continue...";
          cin.get();
          system("cls");
          cout<<endl;
          cout<<"What colour would you like your file's background to be? -"<<endl;
          cout<<endl;
          cout<<"[1] White"<<endl;
          cout<<"[2] Black"<<endl;
          cout<<"[3] Green"<<endl;
          cout<<"[4] Red"<<endl;
          cout<<"[5] Blue"<<endl;
          cout<<"[6] Yellow"<<endl;
          cout<<endl;
          cout<<"[7] Advanced settings..."<<endl;
          cout<<"[0] Randomise!"<<endl;
          cout<<endl;
          cout<<"Colour -"<<endl;
          cout<<"[1/2/3/4/5/6/7/0] : ";
          cin>> bgc;
          
          switch (bgc) {
                 case 1 :
                      (bgcolour = "white");
                      break;
                 case 2 :
                      (bgcolour = "black");
                      break;
                 case 3 :
                      (bgcolour = "green");
                      break;
                 case 4 :
                      (bgcolour = "red");
                      break;
                 case 5 :
                      (bgcolour = "blue");
                      break;
                 case 6 :
                      (bgcolour = "yellow");
                      break;
                 case 7 :
                      cout<<"Advanced settings"<<endl;
                      cout<<endl;
                      cout<<"[8] Specify a different colour"<<endl;
                      cout<<"[9] Use a background image"<<endl;
                      cout<<endl;
                      cout<<"Specify : ";
                      cin>> bgc;
                      
                      if (bgc == 8) {
                              cout<<"Colour : ";
                              cin>> bgcolour;
                              }
                      else if (bgc == 9) {
                           cout<<"Is the file stored online or on your computer? -"<<endl;
                           cout<<endl;
                           cout<<"[1] Hosted on the internet"<<endl;
                           cout<<"[2] Stored locally on your computer"<<endl;
                           cout<<endl;
                           cout<<"Stored [1/2] : ";
                           cin>> stored;
                           
                           if (stored == 1) {
                                      cout<<"Please give the exact URL (address) of the file."<<endl;
                                      cout<<"URL : ";
                                      cin>> bgcolour;
                                      }
                           else if (stored == 2) {
                                cout<<"Please copy the image to the same directory (folder) that this program and htmlwriter.htm are stored."<<endl;
                                cout<<"Then give just the filename of the image you want to use."<<endl;
                                cout<<"File : ";
                                cin>> bgcolour;
                                }
                           else {
                                cout<<"Error. Background set to white."<<endl;
                                }
                                
                           }
                      else {
                           cout<<"Error. Background set to white."<<endl;
                           }
                      break;
                 case 0 :
                      cout<<"Randomising..."<<endl;
                      int randombg;
                      (randombg = 1 + rand() % 6);
                      
                      
                      switch (randombg) {
                             case 1 :
                                  (bgcolour = "white");
                                  break;
                             case 2 :
                                  (bgcolour = "black");
                                  break;
                             case 3 :
                                  (bgcolour = "green");
                                  break;
                             case 4 :
                                  (bgcolour = "red");
                                  break;
                             case 5 :
                                  (bgcolour = "blue");
                                  break;
                             case 6 :
                                  (bgcolour = "yellow");
                                  break;
                             default :
                                     cout<<"Error. Bsckground set to white."<<endl;
                                     break;
                             }
                             
                             
                 default :
                         cout<<"Error. Background set to white."<<endl;
                         break;
                 }
                 
          if (bgc == 9) {
                  myFile<<"<body background='"<<bgcolour<<"'>"<<endl;
                  }
          else {
               myFile<<"<body bgcolor='"<<bgcolour<<"'>"<<endl;
               }
          
          cout<<"Background : "<<bgcolour<<""<<endl;
          cout<<"Finished setting background."<<endl;
          cout<<"Hit [Enter] to continue...";
          cin.get();
          system("cls");
          cout<<endl;
          cout<<"How would you like to align your page? -"<<endl;
          cout<<endl;
          cout<<"|| [1] Left || [2] Centre || [3] Right ||"<<endl;
          cout<<endl;
          cout<<"Align page -"<<endl;
          cout<<"[1/2/3] : ";
          cin>> pal;
          
          switch (pal) {
                 case 1 :
                      (pagealign = "left");
                      break;
                 case 2 :
                      (pagealign = "center");
                      break;
                 case 3 :
                      (pagealign = "right");
                      break;
                 default :
                         cout<<"Error."<<endl;
                         (pagealign = "center");
                         cout<<"Page alignment set to centre."<<endl;
                         break;
                 }
          
          myFile<<"<div align='"<<pagealign<<"'>"<<endl;
          
          cout<<"Page alignment : "<<pagealign<<""<<endl;
          cout<<"Finished setting alignment."<<endl;
          cout<<"Hit [Enter] to continue..."<<endl;
          cin.get();
          cout<<"Would you like to insert an image into your page? [Y/N] : ";
          getline(cin, imgyn);
          cout<<endl;
          
          if (imgyn == "y" || imgyn == "Y") {
                    cout<<"If the file is hosted on the internet, please enter the entire address."<<endl;
                    cout<<"If it is stored locally on your computer, please copy it to the same directory (folder) as htmlwriter.htm."<<endl;
                    cout<<"Then simply put the file name (not the entire address)."<<endl;
                    cout<<"Remember to include the file extension."<<endl;
                    cout<<endl;
                    cout<<"File : ";
                    getline (cin, imgsrc);
                    cout<<"Alternative text : ";
                    getline (cin, alt);
                    cout<<"Hit [Enter] to continue...";
                    cin.get();
                    system("cls");
                    cout<<endl;
                    cout<<"Where would you like to position your image? -"<<endl;
                    cout<<endl;
                    cout<<"[1] To the left"<<endl;
                    cout<<"[2] At the top"<<endl;
                    cout<<"[3] To the right"<<endl;
                    cout<<endl;
                    cout<<"Position -"<<endl;
                    cout<<"[1/2/3] : ";
                    cin>> imgpos;
                    
                    myFile<<"<table border='0' cellpadding='0' cellspacing='2'>"<<endl;
                    
                    switch (imgpos) {
                           case 1 :
                                myFile<<"<tr>"<<endl;
                                myFile<<"<td>"<<endl;
                                myFile<<"<div align='center'>"<<endl;
                                myFile<<"<img src='"<<imgsrc<<"' alt='"<<alt<<"'>"<<endl;
                                myFile<<"</div>"<<endl;
                                myFile<<"</td>"<<endl;
                                myFile<<"<td align='top'>"<<endl;
                                
                                cout<<"Image insterted."<<endl;
                                break;
                           case 2 :
                                myFile<<"<tr>"<<endl;
                                myFile<<"<td valign='top'>"<<endl;
                                myFile<<"<div align='center'>"<<endl;
                                myFile<<"<img src='"<<imgsrc<<"' alt='"<<alt<<"'>"<<endl;
                                myFile<<"<p>"<<endl;
                                myFile<<"</div>"<<endl;
                                
                                cout<<"Image inserted."<<endl;
                                break;
                           case 3 :
                                cout<<"The image will be inserted later."<<endl;
                                break;
                           default :
                                   cout<<"Error."<<endl;
                                   (imgpos = 1);
                                   
                                   myFile<<"<tr>"<<endl;
                                   myFile<<"<td>"<<endl;
                                   myFile<<"<div align='center'>"<<endl;
                                   myFile<<"<img src='"<<imgsrc<<"' alt='"<<alt<<"'>"<<endl;
                                   myFile<<"</div>"<<endl;
                                   myFile<<"</td>"<<endl;
                                   myFile<<"<td valign='top'>"<<endl;
                                   
                                   cout<<"Image inserted to the left."<<endl;
                                   break;
                           }
                    }
          else {
               cout<<"No image was used."<<endl;
               }
               
          cout<<"Hit [Enter] to continue...";
          cin.get();
          system("cls");
          cout<<endl;
          cout<<"Time to configure text settings."<<endl;
          cout<<endl;
          cout<<"How would you like to align your text? -"<<endl;
          cout<<endl;
          cout<<"|| [1] Left || [2] Centre || [3] Right ||"<<endl;
          cout<<endl;
          cout<<"Align -"<<endl;
          cout<<"[1/2/3] : ";
          cin>> txal;
          
          switch (txal) {
                 case 1 :
                      (txtalign = "left");
                      break;
                 case 2 :
                      (txtalign = "center");
                      break;
                 case 3 :
                      (txtalign = "right");
                      break;
                 default :
                         cout<<"Error."<<endl;
                         (txal = 1);
                         (txtalign = "left");
                         cout<<"Alignment set to : left"<<endl;
                         break;
                 }
          
          if (imgyn != "y" && imgyn != "Y") {
                    
                    myFile<<"<table border='0' cellpadding='0' cellspacing='2'>"<<endl;
                    myFile<<"<tr>"<<endl;
                    myFile<<"<td valign='top'>"<<endl;
                    myFile<<"<div align='"<<txtalign<<"'>"<<endl;
                    }
          else {
               
               switch (imgpos) {
                      case 1 :
                           myFile<<"<div align='"<<txtalign<<"'>"<<endl;