Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,124 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,782 people online right now. Registration is fast and FREE... Join Now!




Translating Help!

 
Reply to this topicStart new topic

Translating Help!, VB to C++

kamcmaho
10 Apr, 2007 - 04:13 PM
Post #1

New D.I.C Head
*

Joined: 10 Apr, 2007
Posts: 3


My Contributions
This is my VB code for a program that runs beautifully:

Module modPatterns
CODE

    Sub Main()

        Dim row, astric, space As Integer

        'first pattern
        For row = 1 To 10

            For astric = 0 To (row - 1)
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.WriteLine() 'leaves blank line

        'next pattern
        For row = 1 To 10

            For astric = 0 To (10 - row)
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.WriteLine() 'leaves blank line

        'next pattern
        For row = 1 To 10

            For space = 1 To (row - 1)
                Console.Write(" ")
            Next

            For astric = 0 To (10 - row)
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.WriteLine() 'leaves blank line

        'next pattern
        For row = 1 To 10

            For space = 1 To (10 - row)
                Console.Write(" ")
            Next

            For astric = 1 To row
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.Read() 'stops process so you can view patterns


    End Sub 'Main

End Module 'modPatterns


ok.....
now, I need major help getting it translated to C++...same exact program! I'm soooo freakin' lost!
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Translating Help!
10 Apr, 2007 - 06:08 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,984



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
please use [code ][ /code] tags around your code, please make an attempt and we can help you. Also show us the desired output.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Translating Help!
10 Apr, 2007 - 10:18 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
the shell of your program should look like:
CODE
#include <iostream>
using namespace std;

int main()
{

    return 0;
}


Console.Write("*") becomes cout << '*';
Console.WriteLine() becomes cout <<endl;
For row = 1 To 10 becomes for (row=1; row<=10; ++row)

some notes about syntax:

#1 when you write VB you really should get used to Option Explicit... that is you should declare all of your variables. One reason for this is that C/C++ requires you to declare a variable before you can use it.

#2 the syntax for a for-loop in C/C++ is:
int counter; //declare your variables before you use them

for (initialize ; condition ; step) {iteration code}

initialize: Here is where you initalize your loop.
condition: As long as the condition is true, the loop will continue... so (counter < 10) will continue until counter >10 (at the end of an interation).
step: this ussualy looks like "counter++" or "++counter" (they work the same, the rumer is that the preincrement is faster) but it CAN be any thing that you want. This code will be executed when the iteration step finnishes.
iteration code: The inside of your loop.
example:
CODE
int i;
for (i=0; i<10; ++i) {cout << i+1; } //counts from 1 to 10...


So the loops are a little different.


User is offlineProfile CardPM
+Quote Post

kamcmaho
RE: Translating Help!
11 Apr, 2007 - 02:11 PM
Post #4

New D.I.C Head
*

Joined: 10 Apr, 2007
Posts: 3


My Contributions
QUOTE(kamcmaho @ 10 Apr, 2007 - 05:13 PM) *

This is my VB code for a program that runs beautifully:

Module modPatterns
CODE

    Sub Main()

        Dim row, astric, space As Integer

        'first pattern
        For row = 1 To 10

            For astric = 0 To (row - 1)
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.WriteLine() 'leaves blank line

        'next pattern
        For row = 1 To 10

            For astric = 0 To (10 - row)
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.WriteLine() 'leaves blank line

        'next pattern
        For row = 1 To 10

            For space = 1 To (row - 1)
                Console.Write(" ")
            Next

            For astric = 0 To (10 - row)
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.WriteLine() 'leaves blank line

        'next pattern
        For row = 1 To 10

            For space = 1 To (10 - row)
                Console.Write(" ")
            Next

            For astric = 1 To row
                Console.Write("*")
            Next

            Console.WriteLine() 'writes data to the console
        Next

        Console.Read() 'stops process so you can view patterns


    End Sub 'Main

End Module 'modPatterns


ok.....
now, I need major help getting it translated to C++...same exact program! I'm soooo freakin' lost!



****Here's what the output is supposed to look like:

*
**
***
****
*****
******
*******
********
*********
**********

**********
*********
********
*******
******
*****
****
***
**
*

**********
*********
********
*******
******
*****
****
***
**
*

*
**
***
****
*****
******
*******
********
*********
**********

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Translating Help!
11 Apr, 2007 - 02:20 PM
Post #5

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Nick gave you all the information required to translate it, I believe.
User is offlineProfile CardPM
+Quote Post

kamcmaho
RE: Translating Help!
11 Apr, 2007 - 04:14 PM
Post #6

New D.I.C Head
*

Joined: 10 Apr, 2007
Posts: 3


My Contributions
QUOTE(Amadeus @ 11 Apr, 2007 - 03:20 PM) *

Nick gave you all the information required to translate it, I believe.



thank you guys soooo much!!! great help smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:16PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month