I have a program that erases junk on a floppy disc that is inserted in a drive...
I want to implement a try - catch statement that 'tries' to delete the things on the floppy.. but 'catches' the program if a) there is no floppy in the drive.... or b) there are no fdiles on the floppy....
I have tried numerous websites but they are all hard to follow.. or are tough to relate to my program.. so I was wondering if someone could code one into the code that I already have? so I can learn how it works?
HEre is the code I am working with...
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void getInput();
void erase();
int main()
{
getInput();
//calls the get input function.
}
void getInput()
{
int choice, choice2;
system("cls"); //clears the screen...just to keep it clean.
cout << "This program will clean your floppy of files. 1=continue 2=quit" << endl;
cin >> choice;
if (choice == 1)
{
erase();
}
else
{
cout << "Thank you for playing! Goodbye!" << endl;
system("pause");
return ;
}
}
//end of get input
void erase()
{
int choice2;
system("del A:\\");
cout << " " << endl;
cout << " Do you have more to erase? 1=yes 2=no" <<endl;
cin >> choice2;
if(choice2 == 1)
{
getInput();
// this if statement calls the get input function...whice takes it
// back to the beginning.
}
else
{
cout <<" Thank you for using my program! " << endl;
system("pause");
return ;
}
}
//end of erase
Inside the erase function...the line with: system("del a:\\"); is where I want the statement to be at...
If I were shown how to impliment something like this.. I would much apprechiate it.