• Log in or sign up for an account here: https://www.sythe.org/login

problem with program!!

jman007_93

Member
Joined
Jan 7, 2008
Sythe Gold
0
Messages
63
hey ive only been doing C++ for a little while so dont criticize me or anything. well this is it. what it does is check to see if the number is valid or not. i think it is just bypassing most of the code. no matter what number is entered, it always returns "The number is not valid". please help me. thanx
#include <iostream>
using namespace std;

int main() {
int a; int b; int c; int d; int e; int f; int g; int h;
int i; int j; int k; int l; int m; int n; int o; int p;

cout << "Enter a number and press ENTER: ";
cin >> a;
cout << "Enter a number and press ENTER: ";
cin >> b;
cout << "Enter a number and press ENTER: ";
cin >> c;
cout << "Enter a number and press ENTER: ";
cin >> d;
cout << "Enter a number and press ENTER: ";
cin >> e;
cout << "Enter a number and press ENTER: ";
cin >> f;
cout << "Enter a number and press ENTER: ";
cin >> g;
cout << "Enter a number and press ENTER: ";
cin >> h;
cout << "Enter a number and press ENTER: ";
cin >> i;
cout << "Enter a number and press ENTER: ";
cin >> j;
cout << "Enter a number and press ENTER: ";
cin >> k;
cout << "Enter a number and press ENTER: ";
cin >> l;
cout << "Enter a number and press ENTER: ";
cin >> m;
cout << "Enter a number and press ENTER: ";
cin >> n;
cout << "Enter a number and press ENTER: ";
cin >> o;
cout << "Enter a number and press ENTER: ";
cin >> p;

if (a == 1)
a == 2;
if (a == 2)
a == 4;
if (a == 3)
a == 6;
if (a == 4)
a == 8;
if (a == 5)
a == 1;
if (a == 6)
a == 3;
if (a == 7)
a == 5;
if (a == 8)
a == 7;
if (a == 9)
a == 9;
if (a == 0)
a == 0;

if (c == 1)
c == 2;
if (c == 2)
c == 4;
if (c == 3)
c == 6;
if (c == 4)
c == 8;
if (c == 5)
c == 1;
if (c == 6)
c == 3;
if (c == 7)
c == 5;
if (c == 8)
c == 7;
if (c == 9)
c == 9;
if (c == 0)
c == 0;

if (e == 1)
e == 2;
if (e == 2)
e == 4;
if (e == 3)
e == 6;
if (e == 4)
e == 8;
if (e == 5)
e == 1;
if (e == 6)
e == 3;
if (e == 7)
e == 5;
if (e == 8)
e == 7;
if (e == 9)
e == 9;
if (e == 0)
e == 0;

if (g == 1)
g == 2;
if (g == 2)
g == 4;
if (g == 3)
g == 6;
if (g == 4)
g == 8;
if (g == 5)
g == 1;
if (g == 6)
g == 3;
if (g == 7)
g == 5;
if (g == 8)
g == 7;
if (g == 9)
g == 9;
if (g == 0)
g == 0;

if (i == 1)
i == 2;
if (i == 2)
i == 4;
if (i == 3)
i == 6;
if (i == 4)
i == 8;
if (i == 5)
i == 1;
if (i == 6)
i == 3;
if (i == 7)
i == 5;
if (i == 8)
i == 7;
if (i == 9)
i == 9;
if (i == 0)
i == 0;

if (k == 1)
k == 2;
if (k == 2)
k == 4;
if (k == 3)
k == 6;
if (k == 4)
k == 8;
if (k == 5)
k == 1;
if (k == 6)
k == 3;
if (k == 7)
k == 5;
if (k == 8)
k == 7;
if (k == 9)
k == 9;
if (k == 0)
k == 0;

if (m == 1)
m == 2;
if (m == 2)
m == 4;
if (m == 3)
m == 6;
if (m == 4)
m == 8;
if (m == 5)
m == 1;
if (m == 6)
m == 3;
if (m == 7)
m == 5;
if (m == 8)
m == 7;
if (m == 9)
m == 9;
if (m == 0)
m == 0;

if (o == 1)
o == 2;
if (o == 2)
o == 4;
if (o == 3)
o == 6;
if (o == 4)
o == 8;
if (o == 5)
o == 1;
if (o == 6)
o == 3;
if (o == 7)
o == 5;
if (o == 8)
o == 7;
if (o == 9)
o == 9;
if (o == 0)
o == 0;

if (a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p % 10 == 0)
cout << "The number is valid";
else
cout << "The number is not valid";

return 0;
}
 
Member of the Month Winner
Sythe's 10th Anniversary
that's terrible. You should use arrays, or something similar.

Now what is it exactly that you are trying to do? I can understand that you want to check the remainder of a mathematical operation, but not much more than that.

Your description is extremely unhelpful - check validity due to what? What makes the number valid, etc.?
 
Arrays and loop constructs are your friends :)
 
Holy Christ, that's a lot of integers.

Code:
int a[17];
That's an array, with sixteen slots and one null character to end it. You can store your numbers in there very easily -- just specify which slot you're modifying.

Code:
a[4] = 0;
Also, you use the double = sign, which is for comparisons, you need to use a single = to assign a value.
 
Holy Christ, that's a lot of integers.

Code:
int a[17];
That's an array, with sixteen slots and one null character to end it. You can store your numbers in there very easily -- just specify which slot you're modifying.

Code:
a[4] = 0;
Also, you use the double = sign, which is for comparisons, you need to use a single = to assign a value.

LOLOLOLOLOLOLOL IDIOT! Since when did all arrays end with a null character?
 
thanx. i know about arrays and how to do them, but im a little unsure of how to do it for this. what it does for example is if you input the number 8, it multiplies it by 2, 16, then adds those two digits together giving you 7. it doesnt actually perform this, but it should mean the same thing.

a little more help on arrays for this would be cool.
 
thanx. i know about arrays and how to do them, but im a little unsure of how to do it for this. what it does for example is if you input the number 8, it multiplies it by 2, 16, then adds those two digits together giving you 7. it doesnt actually perform this, but it should mean the same thing.

a little more help on arrays for this would be cool.
Code:
#include <stdio.h>

int i;
int i2;

int main()
{
  printf( "Enter your number." );
  scanf( "%d", i );
  i2 = i;
  i = i * 2;
  i2 = i2 * 16;
  i = i + i2;
  printf( "\nYour number: %d", i );
}

That's how it would work in C (I think).
 
Code:
#include <stdio.h>

int i;
int i2;

int main()
{
  printf( &quot;Enter your number.&quot; );
  scanf( &quot;%d&quot;, i );
  i2 = i;
  i = i * 2;
  i2 = i2 * 16;
  i = i + i2;
  printf( &quot;\nYour number: %d&quot;, i );
}
That's how it would work in C (I think).

From my experience, you never write the string itself in printf, it fucks up flushing.
Code:
printf("%s%d", "Your number: ", i);
is better. And to your question, only with C strings. It signifies EOS (End of String).
 
Member of the Month Winner
Sythe's 10th Anniversary
Don't they have one unusable slot?
Not at all.

All array indices start at 0.

so when you declare
Code:
int a[17];

you may access all elements, they just start at 0.

e.g.
Code:
a[0] = 1;
a[1] = 2;
a[2] = 3;
//etc...
Where my assignments demonstrate which index is what.
 
Not at all.

All array indices start at 0.

so when you declare
Code:
int a[17];
you may access all elements, they just start at 0.

e.g.
Code:
a[0] = 1;
a[1] = 2;
a[2] = 3;
//etc...
Where my assignments demonstrate which index is what.

He's asking if all arrays have one null spot, but only C strings do to signifie end-of-string.
 
He's asking if all arrays have one null spot, but only C strings do to signifie end-of-string.
I don't use C++...
 
Which would be why advice in a C/C++ forum about non-C stuff would be useless, keep up.

You're an idiot, I was just answering your question, douche.
 
Runescape Gamblingrunescape gambling
Back
Top