Hello all
new to programming in general and I'm currently taking my first C++ class. Everything has been going great until I began this assigment. I bascally have to create a program that genreates 3 random numbers (easy) all numbers need to be different (done), print the 3 number as well as the minimum of the three. It has to output like this:
Enter an integer between 10 and 20:
The random numbres are:
The minimum number is:
So far I can generate the numbers but my only problem is I can't figure out how to display them in a row. I also have partially figured out how to display the minimum of the three. Could any one give me some hints or tips?
Code:#include <iostream> #include <iomanip> #include <cstdlib> #include <ctime> using namespace std; int minimum(int, int , int);// function prototype int num1, num2, num3; int main() { const int Numbers = 3; float randvalue; int NUM; cout <<"Enter an integer between 10 and 20: "; cin >> NUM; srand(time(NULL)); for ( int counter = 1; counter <= Numbers; counter++ ) //will loop the number of the times the user entered { randvalue = rand (); cout <<"The random numbers are: "<< ( 1 + rand() % NUM )<<endl; //generates numbers from 1 to the number user entered } cout << "The minimum number is " << minimum(num1, num2, num3)<<endl; system ("pause"); return 0; } // Function minumum definition int minimum( int num1, int num2, int num3) { int min = num1; if ( num2 < min ) min = num2; if ( num3 < min ) min = num3; return min; }



LinkBack URL
About LinkBacks



