problem z zadaniem z Symfonii C++

0

Witam!
Mam takie ćwiczenie:
Napisz program w którym będzie funkcja void f();
Funkcja main ma wywoływać tę funkcję 100 razy. Funkcja f ma wiedzieć ile razy została już wywołana i - przy co dwunastym wywołaniu - wypisywać na ekranie stosowny tekst (np. "nowy tuzin"). I napisałem coś takiego:
#include <iostream>
using namespace std;
void f();
//##################################################################
int main()
{
static int ktory_raz;
int ile;
for (ile=0; ile<100; ile++)
{
ktory_raz++;
void f();
if(ile%12)
{
cout<<"Funkcja wywolana "<<ktory_raz<<" raz"<<endl;

	}
	else
	{
		cout<<"nowy tuzin\n";
	}
}
system("pause");

}
W Dev'ie wszystko mi pięknie wypisuje, lecz w Microsoft Visual C++ 2010 niestety wyskakuje błąd. Dopiero co go ściągnąłem i nie wiem jak to naprawić. :)

0

Jaki błąd? Gdzie jest funkcja f? void f() w mianie to tylko dekalracja że taka będzie. Nie ma nagłówka <csdtlib> potrzebnego do system();

0

jest coś takiego:
'13ggg.exe': Loaded 'C:\Users\Łukasz\Desktop\C++\13\13ggg\Debug\13ggg.exe', Symbols loaded.
'13ggg.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\mscoree.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'13ggg.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\shlwapi.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6001.18523_none_5cdd65e20837faf2\comctl32.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\msvcr100_clr0400.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Culture.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\246f1a5abb686b9dcdf22d3505b08cea\mscorlib.ni.dll', Cannot find or open the PDB file
'13ggg.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'13ggg.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'13ggg.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\Łukasz\Desktop\C++\13\13ggg\Debug\13ggg.exe', Symbols loaded.
'13ggg.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\diasymreader.dll', Cannot find or open the PDB file
'13ggg.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\964da027ebca3b263a05cadb8eaa20a3\System.ni.dll', Cannot find or open the PDB file
'13ggg.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'
The thread 'Win32 Thread' (0x91c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x16d4) has exited with code 0 (0x0).
The program '[5428] 13ggg.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
The program '[5428] 13ggg.exe: Native' has exited with code 0 (0x0).

0

@lukasz2146 czytaj od nowa, bo nic nie zrozumiałeś...

#include <iostream>
using namespace std;
void f();
//##################################################################
int main()
{
  for (int i=0; i<100; i++)
    f();
  cin.sync();
  cin.get();
  return 0;
}

void f()
{
  static int ile = 0;
  if(ile%12)
    cout<<"Funkcja wywolana "<<ile++<<" raz"<<endl;                       
  else
    cout<<"nowy tuzin\n";
}
0

To nie zadziała;D
Po 1 nie deklarowałeś zmiennej ktory_raz;D
Po 2 nawet jak zamienisz ją na zmienną ile to i tak coś jest nie tak,bo dla 100-krotnego wywołania funkcji f() napis powinnien być wyświetlony 8 razy a w tym programie jest o wiele razy więcej ;D
Oto prawidłowy kod:


#include <iostream>
using namespace std;
int ile=0;
void f();
//##################################################################
int main()
{
  for (int i=0; i<100; i++)
    f();
    cout<<endl;
    system("pause");
  return 0;
}
 
void f()
{
  ile+=1;
  if(ile%12==0)
    {
    cout<<"Funkcja wywolana "<<ile<<" raz"<<endl;                       
    cout<<"\nNowy tuzin\n";
}
  else
    cout<<"Funkcja wywolana "<<ile<<" raz"<<endl;
}

0
#include <iostream>
using namespace std;
void f();
int main()
{
  for (int i=0; i<100; i++)
    f();
  cin.sync();
  cin.get();
  return 0;
}
 
void f()
{
  static int ile = 0;
  if(ile%12)
    cout<<"Funkcja wywolana "<<ile<<" raz"<<endl;                       
  else
    cout<<"nowy tuzin\n";
 i++;
}

@mto9 wystarczyło zmienić tyle, co pisali ludzie wyżej..

0

P.S zmienne globalne nie wyglądają za ładnie, lepiej stosować zmienne static.

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