Weegee
Go Weegee!
- Reaction score
- 102
Recently I was learning from a tutorial site and tried to replicate one of their examples. The link to it is here.
The code they used
Their code displays perfectly. I copied it over into my IDE (Visual C++ 2010) and it worked as the example intended. My replicated code:
This displays oddly for me. It displays all of the "Enter number" texts at once (So if i typed that I wanted to enter 2 numbers, it would display "Enter Number" twice and only gives me the option to input once). I think i copied I replicated it correctly, but I might have missed something, does anyone see or know what is wrong with my code? Let me know if you need to know something more
The code they used
PHP:
// rememb-o-matic
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int i,n;
int * p;
cout << "How many numbers would you like to type? ";
cin >> i;
p= new (nothrow) int[i];
if (p == 0)
cout << "Error: memory could not be allocated";
else
{
for (n=0; n<i; n++)
{
cout << "Enter number: ";
cin >> p[n];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
cout << p[n] << ", ";
delete[] p;
}
return 0;
}
PHP:
// Example use of dynamic memory (memory allocated during runtime)
#include <iostream>
#include <new>
using namespace std;
int main ()
{
int i,n;
int * p;
cout << "How many numbers would you like to type? ";
cin >> i;
p= new (nothrow) int[i];
if (p == 0)
cout << "Error: Memory could not be allocated";
else
{
for (n=0; n<i; n++)
cout << "Enter number: " << endl;
cin >> p[n];
}
cout << "You have entered: ";
for (n=0; n<i; n++)
{
cout << p[n] << ", ";
delete[] p;
}
return 0;
}