473,763 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple simple program error...please help

In my simple program I am getting this error..please help

I am trying to find integers where 65537i + 3551j = 1

error: cannot convert `__complex__ int' to `long int' in
assignment
#include <iostream>
#include <complex>
#include <cmath>

using namespace std;

int main ()
{
long x=0;
int y=0;

for (long i=0; i<65537; i++)
{
for (long j=0; j<3511; j++)
{
x=65337i + 3511j;
if (x=1)
cout <<"i: "<< i << " j: "<< j<< endl;
}
}

return 0;
}

Nov 1 '05 #1
14 2176

<ta******@gmail .com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
In my simple program I am getting this error..please help

I am trying to find integers where 65537i + 3551j = 1

error: cannot convert `__complex__ int' to `long int' in
assignment
#include <iostream>
#include <complex>
#include <cmath>

using namespace std;

int main ()
{
long x=0;
int y=0;

for (long i=0; i<65537; i++)
{
for (long j=0; j<3511; j++)
{
x=65337i + 3511j;
What is this? 3511j is not a number. 65537i is probably not a number,
although it might be 65537 as an int.

I think you want x = i + j; here
if (x=1)
cout <<"i: "<< i << " j: "<< j<< endl;
}
}

return 0;
}

Nov 1 '05 #2
ta******@gmail. com wrote:
In my simple program I am getting this error..please help

I am trying to find integers where 65537i + 3551j = 1

error: cannot convert `__complex__ int' to `long int' in
assignment
#include <iostream>
#include <complex>
#include <cmath>
ditch the last two headers: you do not use them anyway.

using namespace std;

int main ()
{
long x=0;
int y=0;

for (long i=0; i<65537; i++)
{
for (long j=0; j<3511; j++)
{
x=65337i + 3511j;
make that:

x= 65337*i + 3511*j;
if (x=1)
probably you mean:

if ( x == 1 )
cout <<"i: "<< i << " j: "<< j<< endl;
}
}

return 0;
}


Also:

a) running the corrected program, you might be in for a little surprise. It
will not find any numbers doing the trick: you are arbitrarily restricted
the search space for i and j, and your bounds are way off (note that it
simply cannot work for i and j both positive!).

b) You might consider reading on GCDs and the Euclidean Algorithm. It can be
extended to solve your problem.

Best

Kai-Uwe Bux

Nov 1 '05 #3
toy
Kai...thanks so much for your advice

why am i restricted? i thought that c++ integers can span a certain
space..along the lines of 2^32..???

i'm familiar with the algorithms, am i required to write my own class
to make this work?

Nov 1 '05 #4
toy wrote:
Kai...thanks so much for your advice
It's Kai-Uwe.

why am i restricted? i thought that c++ integers can span a certain
space..along the lines of 2^32..???
Please quote what you are refering to. I wrote:
a) running the corrected program, you might be in for a little surprise.
It will not find any numbers doing the trick: you are arbitrarily
restricted the search space for i and j, and your bounds are way off
(note that it simply cannot work for i and j both positive!).
And this in not even correct English. I should have written:

.... you arbitrarily restricted the search space for i and j, ...

i'm familiar with the algorithms, am i required to write my own class
to make this work?


*Which* algorithm? To make *what* work?
Best

Kai-Uwe Bux
Nov 1 '05 #5
toy
Kai-Uwe, I apologize for abbreviating your name. If I change the search
space for i and j to count downward, (as in i--, j--)..will this work?

or need i write a class or input code to execute the euclidean
algorithm in some form?

Nov 1 '05 #6
toy
Ok I changed the code to decrement i and j as opposed to
increment...the for loops will also execute until i and j are their
NEGATIVE values.

i still am not generating a solution. can u help?

Nov 1 '05 #7
toy wrote:
Ok I changed the code to decrement i and j as opposed to
increment...the for loops will also execute until i and j are their
NEGATIVE values.

i still am not generating a solution. can u help?


Sure. Here is a simple version of Euclids algorithm:

#include <iostream>
#include <algorithm>

unsigned long gcd_euclid ( unsigned long a, unsigned long b ) {
if ( b < a ) {
std::swap( a, b );
}
while ( a != 0 ) {
// now b = a*q + r for some q and r. (division with remainder)
unsigned long q = b / a;
unsigned long r = b % a;
std::cout << r << " = " << b << " - " << a << "*" << q << '\n';
b = a;
a = r;
}
return ( b );
}

int main ( void ) {
std::cout <<gcd_euclid( 65537, 3551 ) << '\n';
}

If you run this, you find: the output

1619 = 65537 - 3551*18
313 = 3551 - 1619*2
54 = 1619 - 313*5
43 = 313 - 54*5
11 = 54 - 43*1
10 = 43 - 11*3
1 = 11 - 10*1 <--- important information
0 = 10 - 1*10
The magic of the algorithm is that all these equations are actually true.
Now, you can work backwards:

1 = 11 - 10 * 1;
= 11 - ( 43 - 11 * 3 ) * 1 = 11 * 4 - 43
= ( 54 - 43 ) * 4 - 43 = 54*4 - 43*5
= 54*4 - ( 313 - 54*5) * 5 = 313*(-5) + 54*29
= ...

Another way is working forward:

1619 = 65537 - 3551*18
313 = 3551 - 1619*2 = 3551 - ( 65537-3551*18 ) * 2
= 65537*(-2) + 3551*37
54 = 1619 - 313*5
= ( 65537-3551*18 ) - ( 65537*(-2) + 3551*37 ) * 5
= 65537*someting + 3551*something_ else
....
keep going until you get
....
1 = 65537*something + 3551*something_ else
These ideas should get you started.

Best

Kai-Uwe Bux
Nov 1 '05 #8
toy
you are a LIFESAVER

thanks sooo much!

Nov 1 '05 #9
* Kai-Uwe Bux:

[relevant info, gcd]

These ideas should get you started.


Just tell me how you saw what he was trying to do?

Even if it's off-topic.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 1 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3537
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
17
6524
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual interest rate I, and annual service charge S. Your algorithm would then compute and print out the total amount of interest earned during the year and the final account balance at the end of the year (assuming that interest is compounded monthly, and...
5
7246
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files, two aspects which I want to incorporate into my program eventually. That aside, my most pressing problem right now is how to get rid of the newline in the input when I use fgets(). Now I have looked around on the net, not so much in this group...
3
2237
by: kuiyuli | last post by:
I'm using VC++ .Net to do a simlple program. I tried to use <vector> <list> in the program, and I simply put the folowing lines " #include <list> #include <vector> #include <string> using namespace std; ...... vector <Vector> vectorlist;
2
5183
by: Vitali Gontsharuk | last post by:
Hi! I have a problem programming a simple client-server game, which is called pingpong ;-) The final program will first be started as a server (nr. 2) and then as a client. The client then sends the message "Ping" to the server, which reads it and answers with a "Pong". The game is really simple and the coding should be also very simple! But for me it isn't. By the way, the program uses datagram sockets (UDP). And, I'm using
4
3043
by: yogesh | last post by:
mysql in c++ initialize error occurs a simple program is executed in redhat9.0 , using gcc 3.2.2 compiler version ... #include <stdio.h> #include <mysql.h> #include <string.h> int main() {
5
1962
by: Michael | last post by:
Hi All, I have three very simple files as below. When I try and compile these with g++ -ansi -Wall -pedantic -o crap Base.h Other.h I get an error: Base.h:7: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate.
8
3177
by: ftjonsson | last post by:
hello, I was wondering if anyone could tips me on what I am doing wrong when writing the following code: #include <iostream> using namespace std; int main () {
4
1305
by: naveenpadmadas | last post by:
Hi, i have a simple query. I was practising a c program using function by just calling the function. The called function are defined with only printf statements. I tried executing the same program in different desktops having the same configuration.When i execute the program, in some machines, am getting an error message "function should have a prototype", meanwhile some desktops are giving me the output. Can anyone say please what can be the...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.