473,508 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting A Basic Program to A C++ Program

7 New Member
I wrote the following program in Basic. It works in Basic, but I cannot get it
converted to C++. Any help in that direction will be appreciated. The values for
a, S, and R can be changed.

a=3
for S=1 to 5 step 2
R=2
N=((2^R)*S)+1
if int(((a^S)-1)/((2^R)*S+1))=((a^S)-1)/N then print "yes"; "S="; S; "R="; R; "a="; a else print "no"
next S
Mar 27 '10 #1
5 2054
newb16
687 Contributor
If you know the algirithm, reimplement it in C. If A^B is raisong to power, use pow(a,b) function for it.
Mar 27 '10 #2
randysimes
54 New Member
Expand|Select|Wrap|Line Numbers
  1. int a(3), S, R;
  2. for (S=1; S <=5; S+=2)
  3. {
  4. R=2
  5. N=((2^R)*S)+1
  6. if (int(((a^S)-1)/((2^R)*S+1))==((a^S)-1)/N)
  7.  std::cout<< "yes\n"
  8.               << "S= " << S
  9.               << "\nR= " << R
  10.                << "\na= " << a;
  11.  else 
  12.    std::cout << "no";
  13. }
Mar 28 '10 #3
whodgson
542 Contributor
You could write something like the following:
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     double a=3.0,R=2;
  8.     for(int S=1;S<11;S+=2)
  9.     {
  10.         double N=pow(2,R)+1;
  11.         double X=pow(a,S)-1;
  12.         double Y=pow(2,R)*S+1;
  13.         if(X/Y==X/N)cout<<"yes";
  14.         else cout<<"no";
  15.       cout<<"\tS: "<<S<<"\tR: "<<R<<"\ta: "<<a<<endl;      
  16.       }
  17. char q;
  18. cout<<"press any key to continue...";
  19. cin.get(q);
  20. return 0;
//output
/*yes S: 1 R: 2 a: 3
no S: 3 R: 2 a: 3
no S: 5 R: 2 a: 3
no S: 7 R: 2 a: 3
no S: 9 R: 2 a: 3
press any key to continue...*/
Mar 28 '10 #4
whodgson
542 Contributor
Note: The above code emulates the BASIC sphagetti style which would not attract the lowest level of approbation from a C++ professional. In this case two functions should have been used; one a bool type to test the expression and one called to print the yes/no and R,S and a values
Mar 31 '10 #5
bsmath
7 New Member
Thank you for your answer.
Mar 31 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2860
by: John MacDonald | last post by:
I need to convert a string to a integer. I tryed to use the Val() Function but the i need the string to be added. The string is "(x+3)^2" where the x is a part of the for/next statement. And i used...
4
16445
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope...
4
3296
by: Cyde Weys | last post by:
I'm currently working on converting a simulator program from Visual Basic 6.0 to Visual C++ .NET. I've figured out most of the stuff, but there's still one thing I haven't gotten to and I've never...
3
22432
by: Jonny Au | last post by:
Hi everyone, I have a problem about email message format converting. I want to write a program in VB.NET to convert the EML format email message to MSG format, does anyone knows how to do it?...
4
3073
by: Clark Stevens | last post by:
I have a program that I'm converting from VB6 to VB.NET. It reads in a text file containing barcode numbers and their corresponding descriptions. Then the user enters the barcode number and the...
2
2909
by: Marty | last post by:
Hi, I have a very big VB6 program to convert to VB.NET 2003. When I use the ..NET converter, it convert up to a point where the converter just hang and never finish the job. The converter is...
5
10312
by: Testguy | last post by:
Hi, I was wondering if one the smart people that frequent this group could give me a hand with a small program I am attempting to debug. I am not a highly experienced developer, but can...
6
1796
by: Dennis D. | last post by:
Having problems converting Murach's Beginning Visual Basic.net (Prince) and Microsoft Press' Programming Visual Basic.net (Balena) examples for use in VB.net 2005 Express. The VS conversion wizard...
28
3541
by: Randy Reimers | last post by:
(Hope I'm posting this correctly, otherwise - sorry!, don't know what else to do) I wrote a set of programs "many" years ago, running in a type of basic, called "Thoroughbred Basic", a type of...
1
2878
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert...
0
7133
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...
0
7336
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,...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
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...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
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...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.