Jump to content

My program(s)


sciguy
 Share

Recommended Posts

ok, ill do that ( I told ya im still learning, any input is welcome oh, and I use "using namespace std;" so i dont need to add the "std::" in front of cin.

Nope, doesnt work properly like that. Any other options to that and/or system("cls")?

Link to comment
Share on other sites

Hmm...Make a blank string object and have th ecin input to this, like


#include <iostream>

#include <string>

using namespace std


string buff;


int main()

{

cin >> buff;

return 0;

}

It will wait for the user to press enter.

btw: http://www.lazyfoo.net/

Link to comment
Share on other sites

What are you using to program it?

You might have to change some of the properties under "Configuration" if using MSVisual C++ Express edition.

For what sonic said (Which, BTW, is probably not very helpful >_>)

Link to comment
Share on other sites

I fixed the problem. I was using system("pause"), which is an OS function and system dependant. here is the new source code:

#include <iostream>

#include <conio.h>

#include <string>

#include <fstream>

#include <limits>

using namespace std;


string name;

string lname;

char ch;

ifstream inData;

int a;


int main(){

	cout<<"Press enter to continue..."<<endl;

	cin.ignore(numeric_limits<streamsize>::max(), '\n');

	cout<<"Enter your name (first and last):"<<endl;

	cin>>name>>lname;

	system("cls");

	cout<<"Happy birthday "<<name<<" "<<lname<<"!"<<endl<<endl;

	cout<<"Happy birthday to you,"<<endl<<"happy birthday to you,"<<endl;

	cout<<"Happy birthday "<<name<<" "<<lname<<","<<endl;

	cout<<"Happy birthday to you."<<endl;

	cout<<"          s  s  s  s  s"<<endl;

	cout<<"        __|__|__|__|__|__"<<endl;

	cout<<"       |                 |"<<endl;

	cout<<"       |                 |"<<endl;

	cout<<"       {@@@@@@@@@@@@@@@@@}"<<endl;

	cout<<"       |                 |"<<endl;

	cout<<"       |                 |"<<endl;

	cout<<"      @@@@@@@@@@@@@@@@@@@@@"<<endl;

	_getch();

	system("cls");

	inData.open("happybday.txt");

	while (!inData.eof()){

		inData.get(ch);

		cout<<ch;

	}

	inData.close();

	cout<<" "<<endl;


	_getch();

	system("cls");

	cout<<"Thank you for using my program! Hope you enjoyed it!"<<endl;

	cout<<"             -Jared Amos"<<endl;

	_getch();

}

Now I just gotta find a replacement for the system("cls") function

I replaced system("pause") with code that inserts 5 blank lines. (dont worry, I prototyped a fnct, so the code only had to be created once, and I call the function instead of the system pause)

Link to comment
Share on other sites

Good...

When you compiled, did you make sure to choose release configuration if you're using msvc++ express or pro.

Then upload the file out of the 'release' folder.

See the word debug next to the green arrow? Click and select release.

sremupv4.png

Link to comment
Share on other sites

Yeah, I had figured that out... Attached is the release version of the program. after Acmex mentioned it, it hit me I was compiling in debug configuration.happybdayrelease.zip

==========================================================================================================

Here is the code for my newest program, a en/decryption prog. Once I compile and test it, I will upload it if anyone wants a copy but can't compile it themselves.

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

using namespace std;

char inputFile[50];

char outputFile[50];

char inMsg;

int i;

char key;

char outMsg;

string valida;

string validb;


int main(){

	cout<<"Enter the input file"<<endl;

	cin>>inputFile;

	cout<<"Enter the output file"<<endl;

	cin>>outputFile;

	cout<<"Enter key"<<endl;

	cin>>key;

	i=0;

	ifstream MyFile(inputFile);

	ofstream MyOutFile(outputFile);

	while(!MyFile.eof())

{

MyFile.get (inMsg);

valida[i]=inMsg;//Assertion error occurred here

outMsg=inMsg^key;

validb[i]=outMsg^key;

MyOutFile<<outMsg;

i++;

}

	MyFile.close();

	MyOutFile.close();

	cout<<"En/Decryption successfull, checking validity..."<<endl;

	if (valida==validb)

		cout<<"En/Decryption is valid"<<endl;

	else

		cout<<"En/Decryption is invalid, please try again"<<endl;


	return 0;

}

newest code, assertion error occurred at the comment

Link to comment
Share on other sites

Ok, I got the program to work, (thanks to Anon and Addict), but it cuts off part of the end of the file, so the file after decryption is the same as the origional file, but with a few missing characters. Here's the code:

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

using namespace std;

string inputFile;

string outputFile;

char inMsg;

char key;

char outMsg;

char ch;

string valida;

string validb;

ifstream MyFile;

ofstream MyOutFile;


int main(){

	cout<<"Enter the input file"<<endl;

	cin>>inputFile;

	cout<<"Enter the output file"<<endl;

	cin>>outputFile;

	cout<<"Enter key"<<endl;

	cin>>key;

	i=0;


	MyFile.open(inputFile.c_str());

	MyOutFile.open(outputFile.c_str());



	while(!MyFile.eof())

{

MyFile.get (inMsg);

valida+=inMsg;

outMsg=inMsg^key;

validb+=outMsg^key;

MyOutFile<<outMsg;


}

	MyFile.close();

	MyOutFile.close();

	cout<<"En/Decryption successfull, checking validity..."<<endl;

	if (valida==validb)

		cout<<"En/Decryption is valid"<<endl;

	else

		cout<<"En/Decryption is invalid, please try again"<<endl;

	system("pause");


	return 0;

}

here is the origional txt file's contents:

Hello, this is a test file for the en/decryption file.

If you can't read this after encryption, then it was a success!

If you can read it after decryption, it was a success!

If both, it was a success!

So, tell me: did it work?

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

`~!@#$%^&*()-_=+/\|[]{}<>,.;:'"

after encryption the contents of the output file are:

yT]]^EYXBXBPETBEWX]TW^CEYTT_UTRCHAEX^_WX]T;xWH^DRP_ECTPUEYXBPWETCT_RCHAEX^_EYT_XEFPBPBDRRTBB;xWH^DRP_CTPUXEPWETCUTRCHAEX^_XEFPBPBDRRTBB;xWS^EYXEFPBPBDRRTBB;b^ET]]\TUXUXEF^CZ;psrutwvyx{z}|~a`cbedgfihkPSRUTWVYX[Z]\_^A@CBEDGFIHK ;;QOqonmMjlJL

after decryption:

Hello, this is a test file for the en/decryption file.

If you can't read this after encryption, then it was a success!

If you can read it after decryption, it was a success!

If both, it was a success!

So, tell me: did it work?

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

`~!@#$%^&*()-_==

Link to comment
Share on other sites

which program? The birthday card prog should have no errors, all system/OS dependant functions have been removed. The encryption prog works, but is glitchy, a few bytes are missing from the end for some reason. May be the way I write to the file.. Could try to store the output to a string or array then write the whole thing to the file at the same time. For the next version (after I fix this one) I may have it so you type the message into the prog, it encrypts it, then stores it in a binary file. Then you can read the data from the file and decrypt it, viewing it solely in the prog.

Link to comment
Share on other sites

but i only uploaded 1, glad it worked for you, sonic. If anyone can tell what is wrong with my en/decryption prog, feel free to post it.

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.