I am having some trouble with the following code. It is meant to take a string of input and store it in a character array. It should then provide some output, right aligned. This code works fine normally, however when there are spaces , ie ' 's in the input, the output that I have programmed is distorted.
Any suggestions folks,Code:/* main.cpp: The main C++ file for the PowerMath System */ #include <iostream> #include <string> #include <iomanip> using namespace std; char mathInput[100]; string output; int getInput() { cout << "-> "; cin >> mathInput; return 0; } int processInput() { output="Function Error - No Such Function"; } int checkExit() { char exitStr[4] = {'e','x','i','t'}; for(int i = 0; i < 4; i++) { if(mathInput[i]!=exitStr[i]) { return 0; } } } int main() { cout << "PowerMath - Advanced Mathematics System\n\n"; while(checkExit()==0) { getInput(); processInput(); if(checkExit()!=0) {return 0;} cout << setw(80) << output << "\n"; } return 0; }
Regards,
mintsmike