A
A_StClaire_
hey all,
I'm a newb and a moronic one at that. after a day, still can't figure
this thing out. trying to write a simple program that reads a
(C-style) string and then a double til the user types "quit". then it
tells the user what was entered.
first time through the loop is fine. but all times afterward the first
step of reading the string is skipped, and "quit" makes the program
terminate completely.
plz help and thx in advance
#include <iostream>
using namespace std;
class Pair {
static const int max_size = 100;
char c_array[max_size][max_size];
double d_array[max_size];
int i;
int j;
public:
Pair() {
i = 0;
j = 0;
}
void c_read() {
cout << "\nEnter a string. Type 'quit' now to
exit.\n\n";
gets(c_array[i++]);
}
bool c_quit() {
if(!strcmp(c_array[i - 1], "quit")) {
strcpy(c_array[i - 1], "");
return true;
}
return false;
}
void d_read() {
cout << "\nEnter a number.\n\n";
cin >> d_array[j++];
}
void c_write() {
int x = 0;
while(x < i) {
cout << c_array[x++] << endl;
}
}
void d_write() {
int x = 0;
while(x < j) {
cout << d_array[x++] << endl;
}
}
};
int main() {
Pair A;
for( ; ; ) {
A.c_read();
if(A.c_quit()) break;
A.d_read();
}
cout << "\n\nYour entries were:\n\n";
A.c_write();
cout << endl;
A.d_write();
cin.get();
cin.ignore();
return 0;
}
I'm a newb and a moronic one at that. after a day, still can't figure
this thing out. trying to write a simple program that reads a
(C-style) string and then a double til the user types "quit". then it
tells the user what was entered.
first time through the loop is fine. but all times afterward the first
step of reading the string is skipped, and "quit" makes the program
terminate completely.
plz help and thx in advance
#include <iostream>
using namespace std;
class Pair {
static const int max_size = 100;
char c_array[max_size][max_size];
double d_array[max_size];
int i;
int j;
public:
Pair() {
i = 0;
j = 0;
}
void c_read() {
cout << "\nEnter a string. Type 'quit' now to
exit.\n\n";
gets(c_array[i++]);
}
bool c_quit() {
if(!strcmp(c_array[i - 1], "quit")) {
strcpy(c_array[i - 1], "");
return true;
}
return false;
}
void d_read() {
cout << "\nEnter a number.\n\n";
cin >> d_array[j++];
}
void c_write() {
int x = 0;
while(x < i) {
cout << c_array[x++] << endl;
}
}
void d_write() {
int x = 0;
while(x < j) {
cout << d_array[x++] << endl;
}
}
};
int main() {
Pair A;
for( ; ; ) {
A.c_read();
if(A.c_quit()) break;
A.d_read();
}
cout << "\n\nYour entries were:\n\n";
A.c_write();
cout << endl;
A.d_write();
cin.get();
cin.ignore();
return 0;
}