Problem z programem.

0

Zacząłem się uczyć programowania i mam problem z wykonaniem programu.
Ma on generować z wybranego znaku prostokąt (ramkę prostokątną) z użyciem funkcji.
Nie umiem odnaleźć błędu w poniższym programie (odpala się ale nie wykonuje wskazanej operacji)

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;
void szerokosc(int i)
{
int a,n;
char znak;
for (n=0;n<a;n++)
cout << znak;
cout << endl;
}
void wysokosc(int p, int q)
{
char znak;
int m,b,n;
for (m=0;m<b-2;m++)
{
cout << znak;
for (n=0;n<b-2;n++)
cout << " ";

   cout << znak;           
   cout << endl;      
}  

}
int main()
{
char znak;
int c,d;

{
cout<<"podaj znak: ";
cin>>znak;
}

cout << "Szerokosc wynosi ";
cin >> c;

cout << "Wysokosc wynosi ";
cin >> d;

szerokosc(c);
wysokosc(d,c);
szerokosc(c);
cout<<szerokosc<<endl;
cout<<wysokosc<<endl;
cout<<szerokosc <<endl;
getchar();
system("pause");
return 0;
}

2

Może najpierw przeanalizuj wszystkie ostrzeżenia kompilatora:

test.cpp: In function 'void szerokosc(int)':
test.cpp:6:20: warning: unused parameter 'i' [-Wunused-parameter]
    6 | void szerokosc(int i)
      |                ~~~~^
test.cpp: In function 'void wysokosc(int, int)':
test.cpp:14:19: warning: unused parameter 'p' [-Wunused-parameter]
   14 | void wysokosc(int p, int q)
      |               ~~~~^
test.cpp:14:26: warning: unused parameter 'q' [-Wunused-parameter]
   14 | void wysokosc(int p, int q)
      |                      ~~~~^
test.cpp: In function 'int main()':
test.cpp:47:7: warning: the address of 'void szerokosc(int)' will never be NULL [-Waddress]
   47 | cout<<szerokosc<<endl;
      |       ^~~~~~~~~
test.cpp:48:7: warning: the address of 'void wysokosc(int, int)' will never be NULL [-Waddress]
   48 | cout<<wysokosc<<endl;
      |       ^~~~~~~~
test.cpp:49:7: warning: the address of 'void szerokosc(int)' will never be NULL [-Waddress]
   49 | cout<<szerokosc <<endl;
      |       ^~~~~~~~~
test.cpp: In function 'void szerokosc(int)':
test.cpp:10:11: warning: 'a' is used uninitialized in this function [-Wuninitialized]
   10 | for (n=0;n<a;n++)
      |          ~^~
test.cpp: In function 'void wysokosc(int, int)':
test.cpp:18:13: warning: 'b' is used uninitialized in this function [-Wuninitialized]
   18 | for (m=0;m<b-2;m++)
      |            ~^~
test.cpp: In function 'void szerokosc(int)':
test.cpp:9:6: warning: 'znak' may be used uninitialized in this function [-Wmaybe-uninitialized]
    9 | char znak;
      |      ^~~~
test.cpp: In function 'void wysokosc(int, int)':
test.cpp:16:6: warning: 'znak' may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 | char znak;
      |      ^~~~
0

Od ostrzeżeń kompilatora to u Ciebie się aż roi.

1 użytkowników online, w tym zalogowanych: 0, gości: 1