I have a project to complete and i am new to c++ can you assist me.
Here is the question:
1) 1. Create a program that will take an integer number as input from the user and store the number into a two dimensional array, show the user the location of the array that value will be going into. Once the array is full, loop through and display the elements to the screen and finally display the highest number that was entered into the array.
The array will look like this
const int MAX_A = 3;
const int MAX_B = 4;
//declare two dimensional array
int numbers[MAX_A][MAX_B];
my code:
int main()
{
// declaring variables
using namespace std;
int MAX_A = 3;
int MAX_B = 4;
// asking the user to input data & storing in array
cout << "This program will take the user's input and store into an array." << endl;
cout << "Please enter any number, up to a series of 12 numbers..." << endl;
// declaring two-demensional array
int numberArray[MAX_A] [MAX_B];
for (int i=0; i < MAX_A; i++)
for (int j=0; j < MAX_B; j++)
{
cout<<"Enter a number:"<<endl;
cin>>numberArray[MAX_A][MAX_B];
{
if(numberArray>=0);
cout<<"Numbers:"<<numberArray[MAX_A] [MAX_B]<<endl;
if((MAX_A && MAX_B)<0);
cout<<"Error, Please enter a positive real number"<<endl;
break;
if((MAX_A && MAX_B)> 12);
cout<<"Error, you've entered more than 12 numbers"<<endl;
break;
}
#include <iostream>
constint MAX_A = 3;
constint MAX_B = 4;
//declare two dimensional array
int numbers[MAX_A][MAX_B];
int main()
{
// declaring variables
usingnamespace std;
int MAX_A = 3;
int MAX_B = 4;
// asking the user to input data & storing in array
cout << "This program will take the user's input and store into an array." << endl;
cout << "Please enter any number, up to a series of 12 numbers..." << endl;
// declaring two-demensional array
int numberArray[MAX_A] [MAX_B];
for (int i=0; i < MAX_A; i++)
for (int j=0; j < MAX_B; j++)
{
cout << "Enter a number: ";
cin >> numberArray[i][j];
}
//TODO: Your code here..
return 0;
}
int main()
{
// declaring variables
using namespace std;
int MAX_A = 3;
int MAX_B = 4;
// asking the user to input data & storing in array
cout << "This program will take the user's input and store into an array." << endl;
cout << "Please enter any number, up to a series of 12 numbers..." << endl;
// declaring two-demensional array
int numberArray[MAX_A] [MAX_B];
for (int i=0; i < MAX_A; i++)
for (int j=0; j < MAX_B; j++)
// the array takes in the numbers....
{
if(numberArray >=0 ){
cout<<"Enter a number:"<<endl;
cin>>numberArray[i][j];
}
if(MAX_A < 0 && MAX_B < 0 ){
cout<<"Error, Please enter a positive real number"<<endl;
// break;
}
else {
if( numberArray[i][j] > 12){
cout<<"Error, you've entered more than 12 numbers"<<endl;
// break;
system("PAUSE");
}
}
}
}
When i enter a number like 345.. it gives the output "error, you've entered more than 12 numbers"... help me fix this if statement please.
[code][/code] tags please. cin>>numberArray[i][j]; You read a number and stored it in numberArray[i][j]
So the check of being a negative number must be against numberArray[i][j].
Your for loop will only allow MAX_A*MAX_B tries of input (whether they are correct or not)
This operator accepts one parameter, which can be either a type or a variable itself and returns the size in bytes of that type or object.
Why not just have a for loop that has a cin >> and a cin.ignore() in it and not complain if the user inputs too many numbers, but rather just discard the remaining values?