Question: I made a C++ program that works except it's supposed to generate random numbers in the 15-20 range and it doesn't. Here is my code:
I made a C++ program that works except it's supposed to generate random numbers in the 15-20 range and it doesn't. Here is my code:
#include
using namespace std;
int main() { //variable declaration int arr[10],i,temp,j,sum=0; int find,count; float avg; char ch; srand(0); printf(" **Random Number array** "); for(i=0;i<10;i++) { arr[i]=14+rand()%10; //Storing random number in an array printf("%d\t",arr[i]); } while(1) { //Displaying menu & taking choice from user printf(" P. Position R. Reverse A. Average S. Search Q. Quit Your Choice:"); scanf(" %c",&ch); if(ch=='q' || ch=='Q') break; switch (ch) { case 'p': // This case will be executed when choice selected is 'P' or 'p' case 'P': printf(" Array Element postion "); for(i=0;i<10;i++) printf("%d. %d ",i,arr[i]); break; case 'r': // This case will be executed when choice selected is 'r' or 'R' case 'R': j=9; i=0; while(i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
