this original program , can't seem find program causing fail compile:
#include <iostream> using namespace std; int main(){ cout << "how many integers wish enter? "; int inputnums = 0; cin >> inputnums; int* pnumbers = new int [inputnums]; // allocate request integers. int* pcopy = pnumbers; cout << "successfully allocated memory for: " << inputnums << " integers." << endl; (int index = 0; index < inputnums ; ++ index){ cout << "enter number: " << index << ": "; cin >> *(pnumbers + index); } cout << "displaying numbers input: " << endl; for(int index = 0, int* pcopy = pnumbers; index < inputnums; ++index) cout << *(pcopy++) << " "; cout << endl; // done w/using pointers? release memory. delete[] pnumbers; return 0; } any ideas of why isn't working? i've looked , tried insert ';' no avail. redid them in original form ideas appreciated!
these error(s):
main.cpp:20:24: error: expected unqualified-id before 'int' main.cpp:20:24: error: expected ';' before 'int'
your compiler telling error is:
for(int index = 0, int* pcopy = pnumbers; index < inputnums; ++index) does not make sense. problem in first part of for loop:
int index = 0, int* pcopy = pnumbers; the compiler expects after declaring variable, statement ends , second declaration in new statement (although option exists see later):
int index = 0; int* pcopy = pnumbers; this breaks for, expects 1 (simple) statement , 2 expressions. it can fixed writing
int index = 0, *pcopy = pnumbers; which variation on may have seen before:
int a, b; with more complications added in - initialization , fact * not belong type, variable (which weird , great source of errors).
of course not necessary, have pcopy holds right value anyway...
Comments
Post a Comment