C++
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- takezoh
- まろ
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- @tyottyoworks
- ___shanon
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
40
1
2
3
using namespace std;
4
5
int main()
6
7
{ int i=0, j=0;
8
int Stock_Items=3;
9
int NR_materials=3;
10
int total_items=0;
11
int leather_items=0;
12
cout << "Hello user! Welcome to the furniture program \n" << endl;
13
std::cout<<"This program works using a 2 D array \n \n It calculates the amount of stock in the shop and the amount of leather items"<<"\n";
14
//declaration of 2 dimensional array with all items in the shop
15
//This array consists of 3 rows and 3 columns- 3 furniture type and 3 materials
16
int stockArray[Stock_Items][NR_materials]= {{50,10,20},{40,50,60},{30,20,10}};
17
//For loop for calculating total amount of items in the shop
18
for ( i = 0; i < 3; i++ )//rows
19
{
20
for ( j = 0; j < 3; j++ )//columns
21
{
22
total_items+=stockArray[i][j];//sum
23
24
}
25
}
26
27
//For loop for calculating total amount of leather items in the shop
28
for (i=0; i<3; i++)//rows- goes through all rows
29
{
30
for(j=1; j<2; j++)//coloumns- only goes through coloumn 1
31
{
32
leather_items+=stockArray[i][j];//sum
33
}
34
}//display results to the UI
35
std::cout<<"The total amount of stock in the shop is: "<<total_items<<" items. \n \n";
36
std::cout<<"The total amount of leather items is: "<<leather_items<<" items.\n \n";
37
38
return 0;
39
40
}
$ g++ prog.cc -Wall -Wextra -std=c++98 -pedantic
Start
prog.cc: In function 'int main()': prog.cc:16:13: warning: ISO C++ forbids variable length array 'stockArray' [-Wvla] 16 | int stockArray[Stock_Items][NR_materials]= {{50,10,20},{40,50,60},{30,20,10}}; | ^~~~~~~~~~ prog.cc:16:13: warning: ISO C++ forbids variable length array 'stockArray' [-Wvla]
Hello user! Welcome to the furniture program This program works using a 2 D array It calculates the amount of stock in the shop and the amount of leather items The total amount of stock in the shop is: 290 items. The total amount of leather items is: 80 items.
0
Finish