|
-
May 4th, 2007, 07:52 PM
#1
String to Int
I searched the FAQ and found something similar to what I needed but when I tried to incorporate it into my code it didn't work out.
Basically I have a little program that opens up two files, one containing questions, the other containing answers to said questions. Then it randomizes the order and selects 25 of these. Now my problem is that this all uses alot fo arrays and every aray must match the number of lines in the two files. Being the lazy person I am I wanted to be able to make a file, put in the number of lines in each file and then have the program read it and set that as the array size. I've tried opening a file, retrieving the string to an array and turning it into an int, but the problem is that the arrays are global variables and must be declared before I can run any functions (well so far as I know).
Code:
#define normal "normal"
#define practice "practice"
#define yes "yes"
#define no "no"
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <time.h>
#include <Windows.h>
#include <stdio.h>
using namespace std;
string questions[69], answers[69], n_questions[69], n_answers[69], questions_25[25], answers_25[25];
//these are the arrays the questions & answers are stored in
string tchoice2, mi_choice, u_answer, u_status="ERROR", m_choice, time_a;
int j=0, m=0, last, i=0, k=0, q=1, u_wrong=0, w=1, err_check=0, c=0, set_mode=0, ghy=69, ex_chk=0;
int tmd_m=0, h1, h2, m1, m2, s1, s2;
double per_right, u_right=0, versionnum=1.4;
int getanswers(); //retrieve answers from answers.dq
int main_menu(); //main menu when program turns on
int getquestions(); //retrieve questions from questions.dq
int randomizer(); //randomly order questions & answers
int select_25(); //chooses 25 questions & answers from the randomized n_ arrays
int u_help(); //user help menu and articles
int test(); //where the test code lies
int addscores(); //write scores to scores.dq
int norpmode(); //practice or normal mode
int misc_menu(); //miscellaineous menu
int v_info(); //reads version info
int l_questions(); //how many lines are in questions.dq
int l_answers(); // how many answers are in answers.dq
int tmdmode(); //sets timed mode or not
int settime_b(); //starts timer
int settime_e(); //ends timer and figures out how long test took
int u_exit( string e_choice ); //exit feature
int startup();
int main()
{
int startup();
if (ex_chk == 0 )
{
cout << "Welcome, prepping system...\n\n";
string tchoice;
getquestions(); //retrieves questions from questions.dq
last = i;
i = 0;
getanswers(); //retrieves answers from answers.dq
if (err_check != 1)
{
main_menu(); //main menu
while (w==0)
{
randomizer();
select_25();
i = 0;
k = 0;
j = 0;
test();
cout << "\nSave Scores? ";
getline(cin, tchoice2);
if (tchoice2.compare(no) == 0 )
{
}
else if (tchoice2.compare(yes) == 0 )
{
addscores();
}
cout << "\nTake test again? ";
getline(cin, tchoice);
if (tchoice.compare(no) == 0 )
{
w = 1;
}
else if (tchoice.compare(yes) == 0 )
{
norpmode();
}
else
{
cout << "ERROR - 002!\n";
}
}
cout << "\n";
}
system("PAUSE");
return EXIT_SUCCESS;
}
}
Last edited by Cencere; May 4th, 2007 at 08:37 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|