I have to do an assignment for class. Here is what the assignment is:
Start with the following program code. Write the function called "increment" which takes one integer parameter and returns that value plus one.
#include
#include
using namespace std;
// YOUR FUNCTION GOES HERE!
int main()
{
int input;
string keepGoing;
do
{
cout << "Please enter an integer: ";
cin >> input;
cout << "Your number plus one is ";
cout << increment(input);
cout << endl << "Do you want to continue (yes or no)? ";
cin >> keepGoing;
} while ((keepGoing == "yes") || (keepGoing == "YES"));
}
Here is the redone code below and what I have for my answer and basically I just want to make sure I did right. I think I did, but I'm not sure. It runs fine, but not sure if the output is correct. Here is the code:
#include <iostream>
#include <string>
using namespace std;
// The increment function goes here!
int increment (string keepGoing)
{
int total = 0;
for (unsigned int x = 0; x < keepGoing.length(); x++)
{
total = total + 1;
}
cout << endl;
return total;
}
int main()
{
string keepGoing = "increment(keepGoing)";
int input, total = increment(keepGoing);
do
{
cout << "Please enter an integer: ";
cin >> input;
cout << "Your number plus one is ";
cout << increment(keepGoing);
cout << endl << "Do you want to continue (yes or no)? ";
cin >> keepGoing;
} while ((keepGoing == "yes") || (keepGoing == "YES"));
return (0);
}
Again, I just want to make sure I did it right. If it's not correct, what am I missing? I know it's probably something small that I missed as usual...lol. Let me know as soon as you can. It's not due until Wednesday so I have plenty of time to fix it. Thanks for your help :) .