-
Altered counter
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
int num2;
cin >> num2;
{
for(int num2;num2<9999999;num2++)
{
cout<<num2<<endl;
}
return 0;
}
I took the source for a counter from the site tutorial, and then manipulated it so it would count higher, and the user chose the starting number. Why doesn't it work? My compiler won't execute it because of "parse error at end of input", but I can't find anything.
-
You declare num2 twice. Instead, in your loop try doing
for(int num3=num2; num3<9999999; num3++)
{cout<<num3<<endl;}
-
-
O, my bad. You have an extra bracket in there after the input.
-
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
double num2;
cin >> num2;
for(int num3 = num2;num3<9999999;num3++)
{
cout<<num3<<endl;
}
return 0;
}
if you want it to go all the way up to 9999999, num2 should be defined as double. and truly you can do this:
Code:
for(int num3 = num2;num3<9999999;num3++)
cout<<num3<<endl;
-
Thanks. Works now. I am just adding a choice to do negative, etc., so I might need more help.
-
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
double num2;
int num;
cout << "Please input the starting number: ";
cin >> num2;
cout << "1. Positive 2. Negative: ";
cin >> num;
if(num==1)
{
for(double num3=num2; num3<999999999; num3++)
{
cout<<num3<<endl;
}
if(num==2)
{
for(double num3=num2; num3<999999999; num3--)
{
cout<<num3<<endl;
}
return 0;
}
Why doesn't this work. It says the same error as before.
-
Bracket missing
You are missing end } brackets for both of your if statements.
-
-
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
double num2;
int num;
cout << "Please input the starting number: ";
cin >> num2;
cout << "1. Positive 2. Negative: ";
cin >> num;
if(num==1)
{
for(double num3=num2; num3<999999999; num3++)
{
cout<<num3<<endl;
}
}
if(num==2)
{
for(double num3=num2; num3<999999999; num3--)
{
cout<<num3<<endl;
}
}
return 0;
}
I would suggest this:
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
double num2;
int num;
cout << "Please input the starting number: ";
cin >> num2;
cout << "1. Positive 2. Negative: ";
cin >> num;
switch(num)
{
case (num == 1):
{
for(double num3=num2; num3<999999999; num3++)
cout<<num3<<endl;
break;
}
case (num == 2):
{
for(double num3=num2; num3<999999999; num3--)
cout<<num3<<endl;
break;
}
default:
cout << "Invalid";
break;
}
return 0;
}
-
3 compiler errors:
case label `(num == 1)' does not reduce to an interger constant
case label `(num == 2)' does not reduce to an interger constant
warning: unreachable code at beginning of switch statement.
-
sorry
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
double num2;
int num;
cout << "Please input the starting number: ";
cin >> num2;
cout << "1. Positive 2. Negative: ";
cin >> num;
switch(num)
{
case 1:
{
for(double num3=num2; num3<999999999; num3++)
cout<<num3<<endl;
break;
}
case 2:
{
for(double num3=num2; num3<999999999; num3--)
cout<<num3<<endl;
break;
}
default:
cout << "Invalid";
break;
}
return 0;
}
-
Quote:
Originally posted by xlnk
sorry
Code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
double num2;
int num;
cout << "Please input the starting number: ";
cin >> num2;
cout << "1. Positive 2. Negative: ";
cin >> num;
switch(num)
{
case 1:
{
for(double num3=num2; num3<999999999; num3++)
cout<<num3<<endl;
break;
}
case 2:
{
for(double num3=num2; num3<999999999; num3--)
cout<<num3<<endl;
break;
}
default:
cout << "Invalid";
break;
}
return 0;
}
Thanks alot.