我正在尝试按行设置每个数组值的价格。每次程序启动时都必须输入每行的价格。
程序符合但输出不正确,这是显示的内容:
Please enter price for row 0 = 66
please enter row number 0
please enter seat number 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
---------------------------------------------
# * * * * * * * * * * * * * * |0
* * * * * * * * * * * * * * * |1
* * * * * * * * * * * * * * * |2
* * * * * * * * * * * * * * * |3
* * * * * * * * * * * * * * * |4
* * * * * * * * * * * * * * * |5
* * * * * * * * * * * * * * * |6
* * * * * * * * * * * * * * * |7
* * * * * * * * * * * * * * * |8
* * * * * * * * * * * * * * * |9
-858993460
Press any key to continue . . .
不正确的是“-858993460”,它应该显示 66。有人帮我
我的代码看起来像
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
void drawgrid(int ai[10][15], int ji, int ii); // draw grid proto
int numb(int num[10], int tps)
// this function returns back the array possition
// that matchest "tps" ' number
{
return num[0];
}
void numbee(int nu[10])
// this function prompts the user for the price of each row
{
for (int i = 0; i < 10; i++)
{
cout << " Please enter price for row " << i << endl;
cin >> nu[i];
}
return;
}
int printArray(int a[10][15],int tp,int pp)
// this function asks the user what seat to buy
{
int num[10];
cout << "please enter row number ";
cin >> tp;
cout << "please enter seat number";
cin >> pp;
a[tp][pp] = numb(num, tp);
return 0;
}
int main() // this is the main
// calls numbee, drawgrid, and printArray
// sets all to 0 using memset
{
int n[10];
numbee(n);
int love;
int a[10][15];
int i = 0, j = 0;
memset(a, 0, sizeof(a[10][15]) * 10 * 15); // set everything in gridto 0
drawgrid(a, i, j);
love = printArray(a, i, j);
numb(n, love);
drawgrid(a, i, j);
cout << a[0][0];
system("PAUSE");
return 0;
}
void drawgrid(int ai[10][15], int ji, int ii)
// this function draws the gridd
{
ii = 0; ji = 0;
cout << "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ";
std::cout << std::endl;
cout << "---------------------------------------------";
std::cout << std::endl;
for (int ii = 0; ii < 10; ii++) //This loops on the rows.
{
for (int ji = 0; ji < 15; ji++) //This loops on the columns
{
if (ai[ii][ji] == 0)
{
cout << "*" << " ";
}
else
{
cout << "#" << " ";
}
}
cout << "|" << ii;
cout << endl;
}
}