Obviously I am doing something wrong.
Code
void writeProverb(int number)
{
do{
if(number == 1){
cout << "Now is the time for all good men to come to the aid of their party.";}
else if(number == 2){
cout << "Now is the time for all good men to come to the aid for their country.";}
else if(number != 1 && number != 2){
cout << "Input error.";} // If input is not 1 or 2.
} while (number != 1 && number != 2);
}
It is not set in an infinite loop. If I comment out the trailing else if statement I sit at the prompt screen with it blank. Can someone give me a guiding hand?
Entire code: If anyone requires comments for the code let me know.
Code
// Lab 6.2
// Exercise 2:
// This program will allow the user to input from the keyboard
// whether the last word to the following proverb should be party or country:
// "Now is the time for all good men to come to the aid of their"
// Inputting a 1 will use the word party.
// Inputting a 2 will use the word country.
#include <iostream>
#include <string>
using namespace std;
void writeProverb(int);
int main()
{
int wordCode;
cout << "Given the phrase:" << endl;
cout << "Now is the time for all good men to come to the aid of their ____\n\n";
cout << "Input a 1 if you want the sentence to be finished with party." << endl;
cout << "Input a 2 for the word country." << endl << endl;
cout << "Any other input will end in an error. Please input your choice now" << endl;
cin >> wordCode;
cout << endl;
writeProverb(wordCode);
return 0;
}
void writeProverb(int number)
{
do{
if(number == 1){
cout << "Now is the time for all good men to come to the aid of their party.";}
else if(number == 2){
cout << "Now is the time for all good men to come to the aid for their country.";}
else if(number != 1 && number != 2){
cout << "Input error.";} // If input is not 1 or 2.
} while (number != 1 && number != 2);
}
This post was edited by NinjaSushi2 on May 9 2014 07:20pm