Sunday, July 12, 2009

Help c++ programing problem?

//load and save... i hope!!!


#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;


int main()


{


system ("color 2B");


int choice;


int number;





cout %26lt;%26lt; "hi.\n\n\nContinue:1\nNew:2\n\n\n";


cin %26gt;%26gt; choice;





if (choice==2)


{ cout %26lt;%26lt; "\n\nEnter number.";


cin %26gt;%26gt; number;





cout %26lt;%26lt; "Number stored";


}


if (choice==1)


{


cout %26lt;%26lt; "\n\n\nYour number is: ";


cout %26lt;%26lt; number;


}





system ("PAUSE");


return 0;


}





How do I make it to where when the user restarts the program it will display the number they entered before? everytime i try to load a number i entered it always says 49. plzz post





Ive made this post several times with no luck so someone plz post. Also, leave specific details on what I need to add or change. Even if you have to show me the source code that im suppose to have lol.

Help c++ programing problem?
You need to write the number to a file. You have the correct header to do this.. I just don't think you fully understand how to use it. for a full tutorial, go to http://www.cprogramming.com/tutorial/les...





Here's a program for you





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;





using namespace std;





int main(){


system ("color 2B");


int choice;


char number[4];


ofstream thing("number.txt", ios::app);//will make file number.txt


ifstream read;


start:


cout %26lt;%26lt; "Continue:1\nNew:2\n";


cin %26gt;%26gt; choice;





if (choice == 1){


read.open("number.txt");


if (!read){


cout%26lt;%26lt;"We've encountered a problem.. I'm sorry\n";


system("pause");


}


while(read %26gt;%26gt; number){


cout%26lt;%26lt;"Your number is: "%26lt;%26lt; number%26lt;%26lt;endl;


cout%26lt;%26lt;"\n";


read.close();


}


}


else if(choice == 2){


cout %26lt;%26lt; "\n\nEnter number.";


cin %26gt;%26gt; number;


thing %26lt;%26lt; number;


cout%26lt;%26lt;"Number stored";


thing.close();


}


else{


cout%26lt;%26lt;"Invalid choice";


goto start;


}


system("pause");


}








I use dev-c++, just in case this doesn't compile right for you.


No comments:

Post a Comment