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 :) .

#include <iostream>
using namespace std;

int increment(int x){
	return ++x;
}
int main(int argc, char **argv) {
	int x = 3;
	cout << increment(x);
	return 0;
}
commented: Another "here's your homework for you" post. -2

thank you. i appreciate it. i knew it was something simple...lol. I will try it : )

i also have the same assignment and almost the same coding as 'wonderwomen' did. however, what did you mean when you said to add:

#include <iostream>
using namespace std;
int increment(int x){
return ++x;
}
int main(int argc, char **argv) {
int x = 3;
cout << increment(x);
return 0;
}

Write the function called "increment" which takes one integer parameter and returns that value plus one.

so this function is

int increment(int x){
return ++x;
}

it will return x+1

okay. when i use that, i get errors saying cannot convert parameter 1 from 'std::string' to 'int'.

#include <iostream>
#include <string>

using namespace std; 

// The increment function goes here!

      int increment(int x){
      return ++x;
      }

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);

}

hey allialli and ivailosp . This is WonderWomen204 and this is the code I have and it seems to work out ok. Let me know what you think. Thanks.

#include <iostream>
#include <string>


using namespace std;


// The increment function goes here!
int increment (string keepGoing)
{
int total = 1;
for (unsigned int x = 0; x < keepGoing.length(); x++)
{
total++;
}


return total++;
}


int main(int argc, char **argv)
{
string keepGoing = "increment(keepGoing)";
int input, x = 3, 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);
}

This is nothing more than a stupid rehash of another thread that was already answered. No point in doing it again. Just read the previous thread to get the answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.