#8 KIIV
Dakujem - bola chyba v pocte { a } v prvej funkcii.
Příspěvky odeslané z IP adresy 92.52.5.–
Pred funkciou int main() mam uz len jednu funkciu + globalne premenne
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
using namespace std;
void Intro();
void FirstChoice();
void ChangeInfo();
void StockMarketList();
int production();
string FullName;
double Age = 0;
string com;
string building;
int week = 1;
int money = 10000;
int buildings = 1;
int productions = 0;
int AmountOfCommodity = 0;
int AmountOfSelling = 0;
int gain = 0;
int value[7] = {rand()%7,rand()%7,rand()%10,rand()%20,rand()%30,rand()%50,rand()%20};
int x = 0;
string varx;
void BasicGameCycle ()
{
int weeek = 1;
while(money < 350000)
{
AmountOfCommodity + production();
cout << "Week " << week << endl;
cout << "Your production is " << production() << " KG per week. Current balance - " << AmountOfCommodity << endl;
cout << "---------------------------- \n";
if(weeek == 4)
{
StockMarketList();
weeek = 0;
}
week++;
weeek++;
cout << "Invest - INV ---- Buy a " << building << " - BUY ---- Sell - SELL \n";
cin >> varx;
if(varx == "BUY")
{
buildings++;
}
}
Zdravím. Toto sú časti kódu v ktorom mi to vypisuje error "a function definition is not allowed here before { token". Neviem prečo.
int main()
{
srand(time(0));
Intro();
FirstChoice();
ChangeInfo();
cout << "So let's start. Here is the first Stock Market List. Your starting capital is 10 000 dollars. Your goal is 300 000 dollars. It's easy ! \n";
cout << "You will move in weeks. Every 4 weeks you will get list of world's stock market status. Good luck, " << FullName << endl;
StockMarketList();
cout << "Here is your first " << building << ". In the time, you will buy more " << building << "s." << endl;
BasicGameCycle();
return 0;
}
void Intro()
{
double version = 0.1;
cout << "version " << version << endl << endl;
cout << "Welcome to Stock Market Simulator (SMS). Please enjoy. \n" << endl;
cout << "What is your name ? \n";
getline(cin,FullName);
cout << "And your age is ? \n";
cin >> Age;
}
void FirstChoice()
{
cout << "Welcome to SMS " << FullName << endl;
cout << "First you have to choose commodity you wanna trade with. Minerals = easy ----- Fruits = hard \n";
cout << "Minerals : Iron, Copper, Gold, Tin \n";
cout << "Fruits : Apples, Bananas, Lemons \n";
cin >> com;
while(com != "Iron" && com != "Copper" && com != "Gold" && com != "Tin" && com != "Apples" && com != "Bananas" && com != "Lemons")
{
cout << "Please, choose from the list. \n";
cin >> com;
}
cout << "Hmm " << com << " is great choice ! \n";
if (com == "Apples" || com == "Bananas" || com == "Lemons")
{
building = "plantage";
}else{
building = "mine";
}
}
Išlo to v pohode kúsok kódu som zmenil - ani nie v týchto funkciách a zrazu toto...
Kukal som aj na ostatne fora a dozvedel som sa ze sa nema definovat funkcia v inej funkcii.. No nic take tu nie je a stale ten error vypisuje.
Hmm, skusil som to dat ako
cout << "What is your job ? \n";
cin >> job;
namiesto getline(cin, job) a toto funguje ale ked je to nieco zlozene z dvoch slov tak je to v keli, tak teda nevie niekto preco getline v tomto pripade nefunguje a v prvom ano ? :/
Ahoj, som začiatočník, učím sa programovať v c++ a mam menší problém :
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int age = 0;
string job;
cout << "Type in your name please \n";
getline(cin, name);
cout << "Type in your age \n";
cin >> age;
cout << "What is your job ? \n";
getline(cin, job);
cout << "\n";
cout << "PROFILE: \n";
cout << "------------- \n";
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Job:" << job << endl;
cout << "------------- \n";
return 0;
}
Normálne spustím program v konzole a všetko ide až po "What is your job" vypíše to len otázku a potom hneď profil, nedá to priestor na vstup.. A viem že je to primitívne ale naozaj neviem prečo to tak je..
Hod sem zadanie