Jonatan Pieper

Member
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

102 Neutral

About Jonatan Pieper

  • Rank
    Newbie
  1. c++ quiz project (beginner)

    no i want it to update the score all the time im working on that and once you fail/complete the game the score gets saved so it would be a list obv. i will post an update of my code once i've worked a bit more on it i should be fully done in around 4-5 hours hopefully less ^^ and im planning on making it to a return value from each question so that one return points; or such will get "updated" after each question   ok so i dont understand how to make the return points into main i have tried a little which can be seen here: http://ideone.com/dk2IYx   anyone mind explaining to me how to get the return points into main so i only need to save into .txt once and in main only instead of everywhere?
  2. c++ quiz project (beginner)

    ok so i've done some major changes in my code and i hope this one is better i have loads of comments so that might make it difficult to read but here it is:   http://ideone.com/mKKxuy
  3. c++ quiz project (beginner)

    #include <iostream> #include <iomanip> #include <fstream> #include <string> using namespace std; struct highscore{ int svar; }; struct game{ int fraga; int val; }; int main(){ ofstream game; ofstream highscore; bool fail = true; int lost, fraga[10], svar = 0; // these are for the Start option int load ,loadh, loadg, tillbaka; // these are for the loading option string line, line2; // also loading option char val; game.open("game.txt", ios::app); if (!game){ cout << "file could not open"; exit (1); } do{ cout << " Menu" << endl; cout << " 1. Start" << endl; cout << " 2. Load" << endl; cout << " 3. Credits" << endl; cin >> val; switch(val){ case '1': highscore.open("Highscore.txt", ios::app); if (!highscore){ cout << "file could not open"; exit (1); } cout << "WELCOME TO THE CISCO QUIZ GOOD LUCK" << endl; cout << "how many layers are there in the OSI model?" << endl; cout << "1. 4" << endl; cout << "2. 5" << endl; cout << "3. 7" << endl; cin >> fraga; switch(fraga){ case 1: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes and 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 2: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes, 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 3: svar = svar + 5; break; default: cout << "error" << endl; } if(svar == 5){ cout << "what is the full name of OSPF?" << endl; cout << "1. Open Shortest Path First" << endl; cout << "2. Online Shooting Pro Fishing" << endl; cout << "3. On Short Path First" << endl; cin >> fraga; switch(fraga){ case 1: svar = svar + 5; break; case 2: cout << "Game Over!"<< endl; cout << "Do you wish to restart? (answer with 1 for yes, 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 3: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes, 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } } } if(svar == 10){ cout << "What does TTL mean?" << endl; cout << "1. Twin Twitched Life" << endl; cout << "2. Two Time Lives" << endl; cout << "3. Time To Live" << endl; cin >> fraga; switch(fraga){ case 1: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with yes, YES or Yes)"<< endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 2: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes and 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 3: svar = svar + 10; break; } } if(svar == 20){ cout << "What is the first command you enter on a Cisco router?" << endl; cout << " 1. enable"<< endl; cout << " 2. disable" << endl; cout << " 3. enter" << endl; cin >> fraga; switch(fraga){ case 1: svar = svar + 5; break; case 2: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes and 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 3: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes and 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; } } if(svar == 25){ cout << "which protocol is the most prefered?" << endl; cout << " 1. RIP" << endl; cout << " 2. EGRP" << endl; cout << " 3. EIGRP" << endl; cin >> fraga; switch(fraga){ case 1: cout << "Game Over!" << endl; cout << "Do you wish to restart? (answer with 1 for yes and 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 2: cout << "Game Over!"<< endl; cout << "Do you wish to restart? (answer with 1 for yes and 2 for no)" << endl; cin >> lost; if(lost == 2 ){ fail = false; } break; case 3: svar = svar + 15; cout << "You have completed the game press 1 to exit or if you wish to do it again or check highscores press 2" << endl; cin >> lost; if (lost != 1 ){ fail = false; } break; } } highscore <<"Score: " << svar << '\n'; highscore.close(); game << fraga << val; game.close(); cin.ignore(10,'\n'); cin.get(); case '2': cout << "type 1 to load game or type 2 to load highscores" << endl; cin >> load; if (load == 1){ ifstream loadg ("game.txt"); if (loadg.is_open()) { while ( loadg.good() ) { getline (loadg,line2); cout << line2 << endl; } cout << "do you wish to return to the menu press 1 else press any number" << endl; cin >> tillbaka; if (tillbaka != 1){ fail = false; } game.close(); } } else if(load == 2){ ifstream loadh ("highscore.txt"); if (loadh.is_open()) { while ( loadh.good() ) { getline (loadh,line); cout << line << endl; } cout << "do you wish to return to the menu press 1 else press any number" << endl; cin >> tillbaka; if (tillbaka != 1){ fail = false; } highscore.close(); } } cin.ignore(10,'\n'); cin.get(); break; } }while(fail); } so here's the code open to all suggestions   NOTE: have also tried to save the game.txt as a .dat didnt help much tho :S  
  4. c++ quiz project (beginner)

    ok so I have been on other forums, googled, read on most c++ websites and I can't understand how to get my code to save the data to a file which can be selected to loaded once in the game.   I have two ofstreams and ifstreams, one to save and load the highscore of the game the other supposed to save the progress and load it when you feel like it. The thing is I can't get the progress or game to save the data I believe I save it in wrong format and so on but I don't know how to fix that at the moment so I would be really gratefull if someone could help me out here.   I know some of the basics but not all still things I need to get explained but the major problem right now is to get it to save in any format except .txt (was thinking to save it as a .exe first but that didn't work out well so now I'm thinking of something like .dat or .dll or such) Once I get a hang of how to use return properly i will use that and "call" on the things I need to main and not write it all in there but for time being I have done that so it looks messy.   Am using switch-case and in those i have if-else with new switch-cases etc to make the game flow at the moment   Please help me thx   ooh by the way is there a way to remove this post or move it to the beginner c++ section in the for beginner? seems like i cant find the delete button for my topic sry wrong section :(