hey sorry if this comes off as too simple but i am trying to write a simple program and right now i'm only dealing with the I/O but for some reason i am having real trouble inputing a string. The code is a little messy because i have been tryign everythign i can think of to make it work but to no avail. Can someone point out my stupid mistake so i can get back to working on it. THe problem is the geline inside the else
Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void optimal(int len, string input) {}
void least(int len, string input) {}
void first(int len, string input) {}
void clock(int len, string input) {}
int main() {
string input;
char token = ' ', in[256];
int length, other, index = 0, x = 0;
cout << "Welcome to my Caching Algorithm Simulator.\n" << endl;
cout << "Enter 0 for default string or 1 to enter custom stream: ";
length = cin.get();
cout << length << "\n\n";
if (length == '0') {
input = "2 3 2 1 5 2 4 5 3 2 5 2";
}
else {
cout << "Enter your page address stream.\n> ";
cin.getline ( in, 256 );
}
cout << "\nPlease choose your algorithm o(pt), l(ru), f(ifo), c(lock): ";
cout << "\n\n\nKLFD: " << in;
while (x == 0) {
cin >> token;
switch (tolower(token)) {
case 'o': optimal(length, input);
x++;
break;
case 'l': least(length, input);
x++;
break;
case 'f': first(length, input);
x++;
break;
case 'c': clock(length, input);
x++;
break;
default: cout << "\n\nSorry you entered incorrect option." << endl;
cout << "o, l, f, or c: ";
break;
}
}
//print board
return 0;
}