不是C ++专家,但是我正在尽力而为,我有这段代码,我试图要求用户输入1到12之间的数字,无论他们输入什么数字,他们的2D数组都将调整为适合他们的数字,例如:
在过去的几天中,我查看了许多示例,但我无法将其包裹住并将其应用于我的代码。如果有人可以帮助我,我将不胜感激,这是我到目前为止要做的:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <time.h>
#include <vector>
using namespace std;
double Atemp = 0;
double Utemp = 0;
double Working = 0;
double Total = 0;
char Answer = 'x';
int Umain;
const int ROWS = ?;
const int COLS = ?;
typedef float Table[ROWS][COLS];
void displayOverview ();
void playOrQuit();
void outputSubSquare(Table table, int x, int y);
void fillTableWithRands(Table table);
void outputTable(Table table);
void fillIntArray(int array[], int size);
void reverseArray(int array[], int size);
void outputIntArray(int array[], int n);
int main(){
displayOverview();
playOrQuit();
int maxNum = 4;
int intArray[maxNum];
fillIntArray(intArray, maxNum);
outputIntArray(intArray, maxNum);
srand(time(NULL));
Table myTable;
fillTableWithRands(myTable);
outputTable(myTable);
return 0;
}
void displayOverview(){
}
void playOrQuit(){
}
void fillIntArray(int array[], int size){
do{
cout << "Please Enter numbers between 1 and 12: ";
cin >> Umain;
if(Umain <= 12){
for (Utemp = Umain; Utemp > 0; Utemp--){
cout << "Please enter a number between 1 and 4: ";
cin >> Atemp;
for(int i = Atemp; i<0;i++){
cin >> array[i];
}
}
}
else{
cout << "Not within limit :(\n";
}
}
while (Answer == 'y');
}
void fillTableWithRands(Table table){
for(int i = 0; i<ROWS; i++){
for (int j = 0; j<COLS; j++){
table[i][j] = rand()%4+ 1;
}
}
}
void outputTable(Table table){
for(int i = 0; i<ROWS; i++){
for (int j = 0; j<COLS; j++){
cout << table[i][j] << " ";
}
cout << endl;
}
}
void outputIntArray(int array[], int n){
for(int i = 0; i<n; i++){
printf("%d", array[i]);
}
cout << endl;
}
答案 0 :(得分:1)