Hey guys,
I'm new to programming and i need help figuring out this program.
If any one can help me write this program would be great.
Can some show me what they got
Write a C++ program that interactively inputs 15 array values, and then determines the total number of voltages in these ranges: less than 60, greater than or equal to 60 and less than 70, greater than or equal to 70 and less than 80, greater than or equal to 80 and less than 90, and greater than or equal to 90.
Don't post homework questions
Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.
#include <iostream>
usingnamespace std;
int main()
{
int inputArray[15];
//using a loop, get 15 values from the user with cin and put them in inputArray
//use variables to keep count of how many inputs fall into a certain range
int numValsUnder60 = 0;
int numVals60to70 = 0;
int numVals70to80 = 0;
int numVals80to90 = 0;
int numValsAbove90 = 0;
//loop over the input array and increment the range counters accordingly
//print your findings, perhaps?
return 0;
}
Thanks guys, but I already got this program running
That being said I need some help with this one...
Any ideas?
Write a program that generates 50 random numbers of type integer ranges from 1 to 1000 and load all the numbers into a C++ vector. The program should then display the largest, the smallest, the sum, and the average values stored in the vector. Sort the vector in ascending order and display all values on screen.
Here is my 15 values program...
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main()
{
double voltage [3][5];
double row1=0, row2=0, row3=0, row4=0, row5=0;
//Here we input the values
cout<<"Please enter the 15 values for the voltages: "<<endl;
cin>>voltage[0][0];
cin>>voltage[0][1];
cin>>voltage[0][2];
cin>>voltage[0][3];
cin>>voltage[0][4];
cin>>voltage[1][0];
cin>>voltage[1][1];
cin>>voltage[1][2];
cin>>voltage[1][3];
cin>>voltage[1][4];
cin>>voltage[2][0];
cin>>voltage[2][1];
cin>>voltage[2][2];
cin>>voltage[2][3];
cin>>voltage[2][4];
//Sort the values for statement
for (int r=0; r <= 2;r++)
for (int s=0; s <= 4;s++)
{
if (voltage[r][s]<60 && voltage[r][s]>=0)
row1++;
else if (voltage[r][s]>=60 && voltage[r][s]<70)
row2++;
else if (voltage[r][s]>=70 && voltage[r][s]<80)
row3++;
else if (voltage[r][s]>=80 && voltage[r][s]<90)
row4++;
else if (voltage[r][s]>=90)
row5++;
else
cout<<"An improper value was entered."<<endl;
}
//These cout statements create a table of values
cout<<"\nVoltages"<<setw(15)<<"# of Values"<<endl;
cout<<"--------------------------"<<endl;
Can anyone help me with this program:
Write a program that generates 50 random numbers of type integer ranges from 1 to 1000 and load all the numbers into a C++ vector. The program should then display the largest, the smallest, the sum, and the average values stored in the vector. Sort the vector in ascending order and display all values on screen.
Anything would be helpful,
Thanks Guys!