I have to write a complete C++ program, including comments in both the main an din each function, which will do the following:
0. The main program starts by calling a function named introduction which prints out a description of what the program will do. This function is called just once.
This function will not be sent any parameters, and it does not return a value. It will print several lines of output explaining what the program does and how the program and how the program should end.
1. Then the main program asks the user to type in 3 integer values, which could be positive, negative, or zero (see step 4). The main program prints the three integers after they're read in.
2. The main program calls a function named findsmallest, sending it the three integer values. The function will determine the smallest of these three values, sending the answer back to main.
The main program will print the value returned. For example, if you send 4 6 2 to the function, the function will return 2, and the main program will print that 2 is the smallest.
3. The main program will call a function named printmessage, sending it one parameter--the smallest of the integer values. The function will print a message of your choice many times, and the function will not return a value. (BE CAREFUL, SEE BELOW):
For example, if the value of the parameter sent to the function is 2, then the function should print your message 2 times. If the value parameter is 4, the function should print your message 4 times.
However, if the value of the parameter sent to the function is less than or equal to 0, or if the value sent to the function is greater than 10, the function will say it is not possible to print the message.
4. Then the main program will skip a few lines and go back to step 1. At step 1, if the user types in a special combination, the program will go to step 5. You must determine what this combination is and you must explain it--in a prompt and in a comment and in the introduction at the beginning--to the person using the program.
5. At the end, print how many sets of three data values were entered and processed. (Make sure that this number is at least 10.)
YOU WILL BE JUDGED ON THE QUALITY OF YOUR DATA
Type in a total of at least 10 sets of data values.
Have at least one set where all three numbers are equal.
Have the smallest be 1 one time, and have the smallest be 10 one time.
Have at least two sets where the smallest number is either 0 or negative, so that your message is not printed.
Have at least two sets where the smallest number is above 10, so that your message is not printed.
Have at least six sets where you do print your message one or more times.
STYLE: Be sure that each function has a good comment explaining two things: exactly what parameter(s) the function will receive, and exactly what the function will do (and if it returns an answer or prints). For each function, mention the function's parameters by name in the comment.
OUTPUT: Here is some sample output (ignoring the introduction):
the three original integers are -5, 3, -5
the smallest number is -5
it is not possible to print the message in this case
the three original integers are 4, 5 , 3
the smallest number is 3
yourmessage
yourmessage
yourmessage (your message is printed 3 times)
What have you written so far? Make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
Carefully read through the assignment. As you do so, create a sketch of your code. If you don't know exactly how to do something, put comments in describing it. When you get to the end, go back to the beginning to see if you've got everything. Then work on making the code compile and run.
Finally, and this is very important, go back through the assignment and your code again to make sure you have everything.
I'll help you get started with the first few points:
0. The main program starts by calling a function named introduction which prints out a description of what the program will do. This function is called just once.
This function will not be sent any parameters, and it does not return a value. It will print several lines of output explaining what the program does and how the program and how the program should end.
1 2 3 4 5 6 7 8 9
void introduction()
{
// print out a description of the program
}
int main()
{
introduction();
}
1. Then the main program asks the user to type in 3 integer values, which could be positive, negative, or zero (see step 4). The main program prints the three integers after they're read in.
Okay, so now main is:
1 2 3 4 5 6 7 8 9 10
int main()
{
introduction();
// prompt for 3 integers and print them out
int a, b, c;
cout << "Enter 3 numbers: ";
cin >> a >> b >> c;
cout << "You entered " << a << " " << b << " " << c << '\n';
}
2. The main program calls a function named findsmallest, sending it the three integer values. The function will determine the smallest of these three values, sending the answer back to main.
So the prototype for findsmallest is like this:
1 2 3 4
int findsmallest(int a, int b, int c)
{
// return the smallest value of a, b, and c.
}
and you call it in main to find the smallest value: int smallest = findsmallest(a, b, c);
The main program will print the value returned. For example, if you send 4 6 2 to the function, the function will return 2, and the main program will print that 2 is the smallest.
Okay, so after you get the smallest, you print it out:
1 2
int smallest = findsmallest(a, b, c);
cout << "The smallest number is " << smallest << '\n';
#include <iostream>
using std::cout;
using std::cin;
int main()
{
//arbitrary vals
double a{};
double b{};
double c{};
cout << "enter 2 numbers: " << '\n';
cin >> b >> c;
cout << "\n\ta = " << a << "\tb = " << b << "\tc = " << c << '\n';
//This is equivalent to the if else, bit less cumbersome
a = b > c ? b - c : 0;
cout << "\ta = " << a << '\n';
return 0;
}
Hopefully this doesn't confuse.
Step through with F10 in visstud to see things more clearly.
You can learn a lot more using vis stud rather than, say, code::blocks.
I started the same program but a different way but I'm stuck
//This program will read in three integers
#include <iostream>
void introduction (void);
int findsmallest (int, int, int);
int printmessage (int);
using namespace std;
void introduction(void)
{
//Print out a program to find the smallest integer
}
int main()
{
introduction();
//Prompt for 3 integers and print them out
int a, b, c;
cout << "Enter 3 integers: ";
cin >> a >> b >> c;
cout << "I entered " << a << " " << b << " " << c << endl;
}
int findsmallest (int a, int b, int c);
{
findsmallest();
//Return the smallest value of a, b, c
int findsmallest (a, b, c);
cout << "The smallest numbers is " << smallest << endl;
}
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
//This program will read in three integers
#include <iostream>
void introduction (void);
int findsmallest (int, int, int);
int printmessage (int);
usingnamespace std;
void introduction(void)
{
//Print out a program to find the smallest integer
}
int main()
{
introduction();
//Prompt for 3 integers and print them out
int a, b, c;
cout << "Enter 3 integers: ";
cin >> a >> b >> c;
cout << "I entered " << a << " " << b << " " << c << endl;
}
int findsmallest (int a, int b, int c);
{
findsmallest();
//Return the smallest value of a, b, c
int findsmallest (a, b, c);
cout << "The smallest numbers is " << smallest << endl;
}
int printmessage (int)
{
}
Please at least take the time answer the question: what specifically are you stuck with?
Then the main program will skip a few lines and go back to step 1. At step 1, if the user types in a special combination, the program will go to step 5. You must determine what this combination is and you must explain it--in a prompt and in a comment and in the introduction at the beginning--to the person using the program.
Which part specifically? You're being extremely evasive in asking for help.