-
I've know idea why you were using chars, try this. If I've got these code tags right.
Code:
#include <iostream.h>
int main(void)
{
int min,max,i;
cout << "Input your first number to count from: ";
cin >> min;
cout << "Input your last number to count to: ";
cin >> max;
for(i=min; i <= max; i++)
cout << i << endl;
system("pause");
return 0;
}
-
yeah - the tutroial im using doesnt use chars - so they were confusing me !!
tried that code
Compiling...
mark.cpp
C:\Documents and Settings\Default\Desktop\test\mark.cpp(16) : error C2065: 'system' : undeclared identifier
Error executing cl.exe.
mark.exe - 1 error(s), 0 warning(s)
Its just not my day is it
-
Take out the system code. That should work
-
yeah it compiles fine now...
But i am back to step one where it executes
Mark
-
Frankly, I don't know what is wrong now.
-
Use this
Code:
#include <iostream.h>
int main(void)
{
int min,max,i;
cout << "Input your first number to count from: ";
cin >> min;
cout << "Input your last number to count to: ";
cin >> max;
for(i=min; i <= max; i++)
cout << i << endl;
getchar();
return 0;
}
-
You are using MSVC++? Well then to save some trouble, when you want to test your program, press CTRL+F5 to have MSVC++ execute the program for you, plus if it's a console app (dos screen), it will automatically "pause" when it's finished
just FYI
-
if you are using VC++ try this
Code:
#include <iostream.h>
int main(void)
{
int min,max,i;
cout << "Input your first number to count from: ";
cin >> min;
cout << "Input your last number to count to: ";
cin >> max;
for(i=min; i <= max; i++)
cout << i << endl;
cout<<"\n Press a key to continue ";
getch();
return 0;
}
-
Compiling...
Counting.cpp
c:\documents and settings\default\desktop\c++\for loop\counting.cpp(17) : error C2065: 'getch' : undeclared identifier
Error executing cl.exe.
:mad:
-
Code:
#include <iostream>
int main(void)
{
int min,max,i;
cout << "Input your first number to count from: ";
cin >> min;
cout << "Input your last number to count to: ";
cin >> max;
for(i=min; i <= max; i++)
cout << i << endl;
cout<<"\nPress a key to continue ";
while (cin.get() != '\n');
cin.get();
return 0;
}
This works for me and should work everywhere.
Add using namespace std; like in one of the previous messages if this does not work. Generally one should use std:: before all the cout:s and cin:s.