When I run this program using the F or R choice the first output repeats twice, and I can't figure out why. The rest of the program works great.
Prog8.cpp
#include "stdafx.h"
#include "ModifyT.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
char ch;
char exitLetter;
char line[101];
ModifyT modifytext;
cout << "Please enter R to reverse the string, and F for a normal string: ";
cin >> ch;
while (ch == 'f' || ch == 'F' ) {
cout << "Type a Phrase: ";
cin.getline(line, 101);
exitLetter = line[0];
if (exitLetter == 'y' || exitLetter == 'Y') {
return(0);
}
if (exitLetter == 'x' || exitLetter == 'X') {
modifytext.PrintF(line);
}
}
while (ch == 'r' || ch == 'R') {
cout << "Type a Phrase Under 100 Characters: ";
cin.getline(line, 101);
exitLetter = line[0];
if (exitLetter == 'y' || exitLetter == 'Y') {
return(0);
}
if (exitLetter == 'x' || exitLetter == 'X') {
modifytext.PrintR(line);
}
}
}
ModifyT.cpp
#include "stdafx.h"
#include "ModifyT.h"
#include <iostream>
#include <string>
using namespace std;
void ModifyT::PrintF(string text) {
cout << text << endl;
}
void ModifyT::PrintR(char *textPtr) {
char *p = textPtr;
while ( *p != '\0' ){
++p;
}
while ( p != textPtr ) {
cout.put ( *--p );
}
cout << "\n";
}
ModifyT.h
#ifndef _MODIFYT_H
#define _MODIFYT_H
#include <string>
using namespace std;
class ModifyT
{
public:
void PrintR(char *);
void PrintF(string);
};
#endif /* _MODIFYT_H */
Any help would be appreciated.