#include <iostream>;
#include <cstdlib>;
#include <ctime>;
usingnamespace std;
int main()
{
//create a generation's seed by the time
srand(time(0));
int choice;
do
{
std::cout << "-=Number Generator=- \n \n 1. Generate truely numbers \n 2. Generate a number between 2 numbers" << "\n ";
std::cin >> choice;
std::cout << endl;
} while (!(choice == 1 || choice == 2));
int gen_num;
//option 1
if (choice == 1)
{
std::cout << "How many number(s) you want to generate ? ";
std::cin >> gen_num;
gen_num += 1;
for (int x = 1; x < gen_num; x++)
{
std::cout << x << ". " << rand() << "\n";
}
}
int num_min_gen;
int num_max_gen;
//option 2
if (choice == 2)
{
std::cout << "\n What is the smaller number you want to generate ? ";
std::cin >> num_min_gen;
std::cout << "\n What is the taller number you want to generate ? ";
std::cin >> num_max_gen;
std::cout << "\n How many number(s) you want to generate ? ";
std::cin >> gen_num;
gen_num += 1;
for (int x = 1; x < gen_num; x++)
{
std::cout << x << ". " << num_min_gen + (rand() %num_max_gen) << "\n";
}
}
//end of the program
std::cout << "\nPress ENTER to quit...";
std::cin.get();
std::cin.get();
return 0;
}
I have some suggestions for improving your formatting of the code.
- Remove any unnecessary space, make the length (number of lines) as compact as possible.
- Try to always put your variable declaration at the top.
- If you're writing std:: before everything, you don't need to use 'using namespace std;'
Try to always put your variable declaration at the top.
Bad advice. Declare variables when they are needed. Clumping them up is just really bad practice, take advantage of the fact that you can declare them anywhere in c++.
How is it bad to organize the variables from everything else in the code? Being able to declare them anyway doesn't mean it's good to declare them anywhere...