Hey guys! I have one question. I made this code and it has 'several' issues. Don't mind the text that you don't understand, it is because it is in my native language and I tried to make a program that would ask you a question (those axs, xsa similiar). First you'd have to choose a category, and then it asks you a question. See for yourself where I was wrong and correct me:
#include "stdafx.h" #include <iostream> #include <fstream> #include <ctime> #include <cmath> #include <cstdlib> #include <cstring> #include <string> #define MAX_PATH 10000 using namespace std; void question(int n, int i, int x); int rand0toN1(int n); int rand0toI1(int i); int rand0toX1(int x); int main(){ int i, n, x; char izbor[MAX_PATH + 1]; srand(time(NULL)); cout << "Izaberite Kolokvijum1(K1), Kolokvijum2(K2), ili Ispit(I): "; back: cin.getline(izbor, MAX_PATH); if (izbor == 'K1' || izbor == 'k1'){ cout << "Pitanje je: " << questions1[i] << endl; system("PAUSE"); return 0; } if (izbor == 'K2' || izbor == 'k2') { cout << "Pitanje je: " << questions2[n] << endl; system("PAUSE"); return 0; } if (izbor == 'i' || izbor == 'I'){ cout << "Pitanje je: " << questions3[x] << endl; system ("PAUSE"); return 0; } else{ cout << "Neispravan unos. Molimo unesite izbor opet: "; goto back; } } void question(int n, int i, int x){ char *questions1[2] = {"asd", "asf"}; char *questions2[2] = {"zxc", "zxv"}; char *questions3[4] = {"asd", "asf", "zxc", "zxv"}; n = rand0toN1; i = rand0toI1; x = rand0toX1; } int rand0toN1(int n){ return rand() % n; } int rand0toI1(int i){ return rand() % i; } int rand0toX1(int x){ return rand() % x; }
And this is DA ERRORZZ :D
---- Build started: Project: ConsoleApplication15, Configuration: Debug Win32 ------ ConsoleApplication15.cpp c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(22): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(28): error C2446: '==' : no conversion from 'int' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(28): error C2040: '==' : 'char [10001]' differs in levels of indirection from 'int' c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(29): error C2065: 'questions1' : undeclared identifier c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(33): error C2446: '==' : no conversion from 'int' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(33): error C2040: '==' : 'char [10001]' differs in levels of indirection from 'int' c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(34): error C2065: 'questions2' : undeclared identifier c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(38): error C2446: '==' : no conversion from 'int' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(38): error C2040: '==' : 'char [10001]' differs in levels of indirection from 'int' c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(39): error C2065: 'questions3' : undeclared identifier c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(55): error C2440: '=' : cannot convert from 'int (__cdecl *)(int)' to 'int' There is no context in which this conversion is possible c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(56): error C2440: '=' : cannot convert from 'int (__cdecl *)(int)' to 'int' There is no context in which this conversion is possible c:\users\ilija\documents\visualstudio\projects\consoleapplication15\consoleapplication15\consoleapplication15.cpp(57): error C2440: '=' : cannot convert from 'int (__cdecl *)(int)' to 'int' There is no context in which this conversion is possible ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I don't know what is wrong, because I'm learning C++ for about 3 months and this is the summary of what I know (If you take out the file storage and classes). If anyone could help me, that would be great. :)