valestrom 17 Junior Poster in Training

Wow, that was such a big help. I was thinking of using a for loop but I couldn't find a way to implement it! Now I just have to edit it to work with my other functions and it should do the trick. Thanks so much.

valestrom 17 Junior Poster in Training

I was hoping to do it all in one function. Is that out of line?

valestrom 17 Junior Poster in Training

My program is supposed to replace all sets of 4 spaces with a tab but it only seems to be editing the first line then skipping the rest of the lines. "work_string" is defined via another function which takes and saves an entire files input into one string. I just can't get my replacing function to act on multiple lines instead of just the first one.

Here's my replacing function, anyone have an idea of how to get it to act on every line of "work_string"?

def space_to_tab(work_string):
    s_to_tab = 4

    whitespace = work_string[ : len(work_string) - len(work_string.lstrip())]
    whitespace = whitespace.replace(REAL_SPACE * s_to_tab, REAL_TAB)
    whitespace = whitespace.lstrip(REAL_SPACE)
    result = whitespace + (work_string.lstrip())
    return result
valestrom 17 Junior Poster in Training

So I have it reading partially now, but it stops after reading a set of lines. The output stops at line 21. Can someone explain this, here's the whole program.

#Name: Nathan Geist
#ID #: *******
#Tut: 06

#Assignment 3
#Code Editing Program:

# 1) Change tabs in the indenting to spaces
# 2) Change spaces in the indenting to tabs
# 3) Substitute spaces, tabs, and newlines for printable characters
# 4) Undo 3
# *Functions will not be used at the same time*
# *Using command line qualifiers to allow user to specify functions to use*
# *Using a (-) sign to introduce a short qualifier*

#Imports
import sys

#Defining Constants
EOF = chr(4) # Standard End of File character
TAB_CHAR = chr(187) # ">>" character used to make tab character visible
SPACE_CHAR = chr(183) # Raised dot used to make space character visible
NEWLINE_CHAR = chr(182) # Backwards p used to make newline character visible

#Input

def get_input():
    """This function works like input() (with no arguments) except that
    instead of throwing an exception when encountering EOF it will return an
    EOF character (char(4))
    Returns: a line of input or EOF if end of file"""

    try:
        ret = input()
    except EOFError:
        ret = ret+EOF
    return ret


#Tabs to spaces
def tab_to_space(file_in):
    """ This function changes tabs in the indenting to spaces
    """
    print("Tabbing spaces")
    output_string = ""

    for line in file_in:
        input_string = get_input()
        input_string = input_string.replace("/t", "    ")
        output_string = output_string+input_string

    return output_string



def help():
    """Prints …
valestrom 17 Junior Poster in Training

Oh you know what I called the input statement but I had in fact written my own input statement for the program that tests for EOF.

valestrom 17 Junior Poster in Training

Hey, I'm trying to figure out how to get this kind of program to work, it's supposed to be a UNIX style program in the sense that everything is command line driven. What I'm trying to get it to do is when the function is called it takes the input file and converts all tabs into 4 spaces. Here's the form of the input and what I have of my tab_to_space function so far.

"python3 assignment3.py +t < assignment3.py > output.txt"

Where +t denotes the function that is being called

Here is my function so far.

def tab_to_space():
    """ This function changes tabs in the indenting to spaces
    """
    print("Tabbing spaces")
    for TAB_CHAR in input():
        string = input()
        string.replace("   ", "    ")
        return string
valestrom 17 Junior Poster in Training

That sounds so smart, I talked to my prof and he suggested the same kind of thing. Just without hard code in the example. Thanks!

valestrom 17 Junior Poster in Training
print ("The scope of this program is to multiply two matrices together\
and print the result")


while True:
    matrix1_rows = input("How many rows does matrix one have? ")
    matrix1_columns = input("How many columns does matrix one have? ")

    print ("Matrix one is a", matrix1_rows, "x", matrix1_columns, "matrix")
    print()

    matrix2_rows = input("How many rows does matrix two have? ")
    matrix2_columns = input("How many columns does matrix one have? ")

    print ("Matrix two is a", matrix2_rows, "x", matrix2_columns, "matrix")

    if(matrix1_columns != matrix2_rows):
        print("\nSorry, cannot multiply these two matrices, must be (mxn)*(nxp)")


    else:
        break


print("----------------------------------------------------------")
print("\nThe system will now take values for matrix one, one row at a time")
print("Enter the values of the first row, click enter then the second row, and so on")

for i in range (0, int(matrix1_rows)):

        if (i == 0):
            matrix1_row1_set = input("Please enter the values for the row\n")

I want to be able to have the user enter the number of rows that the matrix has and then ask for each rows value (Like user entering "1 0 5 9 5") and assigning that to the variable matrix1_row1_set then getting another row and assigning it to a variable like matrix1_row2_set

What would be the most efficient way to do this?

valestrom 17 Junior Poster in Training

Yeah I'm all used to C++/C# error codes which I can more less pick out. Java is a new deal to me.

valestrom 17 Junior Poster in Training

Oh wow. Didn't even make the link. Thanks for the fix!

valestrom 17 Junior Poster in Training

May sound all too easy for some, but I'm just getting started on android development and I can't find out why I got an error when everything is exactly as it is in the tutorial. Weird but I'm confused so I thought I'd post to see if someone can help me out here.

Error is: Gradle: error: cannot find symbol variable container at line (23,30)

MainActivity.Java

package com.example.myfirstapp;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" …
valestrom 17 Junior Poster in Training

I'm working on a simple updater program that gets text from a file called version.dv that will always have a number in the form of 1.00, 1.15, 2.00
I can't figure out how to get it to read the file and save the text to a string though. Here's what I have, but I have no idea where to go. If anyone has ideas, I would be in your debt.

 private void button2_Click(object sender, EventArgs e)
        {
            //Open Version.DV
            //Check number (1.00)
            //If number is less, update. If not, switch to play now.

               using (StreamReader sr = new StreamReader("c:\\version.DV")) 
            {
                String line;
                // Read and display lines from the file until the end of 
                // the file is reached.
                while ((line = sr.ReadLine()) != null) 
                {
                    Console.WriteLine(line);
                }
                double linevalue = Convert.ToDouble(line);
                if (linevalue > 3.00)
                {
                    Application.Exit();
                }
                else
                {
                    mainbut.Text = "Play!";
                }
            }
        }
valestrom 17 Junior Poster in Training

Basically what I want to do is when the user browses and finds the file he wants to add the extension to I use a button click to add a .NOPE extension or something like that. I have no idea how to get it to find the end of the text and add that though. Help would be greatly appreciated!

valestrom 17 Junior Poster in Training

It is probably a simply typo. The string conversion produces a .NET string of type System::String^, not a C++ string of type std::string. If you use the lower-case name string, my guess is that it refers to std::string, which is not the same as System::String^. This should work:

System::String^ makebreak1 = makebreak.ToString();

If you want a C++ string, then you will have to marshal the .NET String.

Absolutely beautiful. Thanks mike, and everyone else who contributed as well! Helping me understand more and more.

valestrom 17 Junior Poster in Training

I can't figure out how to convert my int value back to a string for use in a textbox. I already pulled it out converted it to int, did the equation now I just want to flip it back to display in a textbox.

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

                int cost = Convert::ToInt32(costbuy->Text);
                int amount = Convert::ToInt32(amountb->Text);
                int costnow = Convert::ToInt32(nowcost->Text);
                int frontcost = cost*amount;
                int endcost = costnow*amount;
                int makebreak = endcost-frontcost;
                string makebreak1 = makebreak.ToString();
                ;
                end->Text = makebreak;

             }

It's a stock value calculator if that helps make sense of the code.

valestrom 17 Junior Poster in Training

So I'm making this website off a template, but I recently came across a problem. If I insert the Webstunning Gallery I got it appears overtop my sidebar when it stretches out, so I can't see the navigation. Is there any way to send the flash document to a more bottom layer instead of being on top, or make the sidebar always appear on top? I'm using Dreamweaver CS5.5 and here's the long code for this page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- #BeginTemplate "../../Templates/template.dwt" -->

<head>
<!-- #BeginEditable "meta" -->
<title>WL Plastics - Foran Equipment</title>
<meta name="Keywords" content="place your keywords here" />
<meta name="Description" content="place a description for your webpage here" />
<!-- #EndEditable -->

<!-- language content -->
<meta name="language" content="en-US" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

<!-- shared style sheets -->
<link href="../../Site/styles/template.css" rel="stylesheet" type="text/css" />
<link href="../../Site/styles/common.css" rel="stylesheet" type="text/css" />

<!-- IE6 style -->
<!--[if lte IE 6]> 
    <script>
    document.write('<link href="Site/styles/ie6.css" rel="stylesheet" type="text/css" />')
    </script>
        <noscript>
        <link href="../Site/styles/ie6.css" rel="stylesheet" type="text/css" />
        </noscript>
<![endif]-->
<!-- IE7 style -->
<!--[if lte IE 7]> 
    <script>
    document.write('<link href="Site/styles/ie7.css" rel="stylesheet" type="text/css" />')
    </script>
        <noscript>
        <link href="../Site/styles/ie7.css" rel="stylesheet" type="text/css" />
        </noscript>
<![endif]-->

<!-- alternate style -->
<!-- #BeginEditable "alternate style" -->
<link href="../../Site/styles/alternate/alternate2.css" rel="stylesheet" type="text/css" />
<!-- #EndEditable -->

<!-- #BeginEditable "flash_variables" -->
<script type="text/javascript">
// if this page is in:
//   the root folder, then set this variable to ./
//   a sub folder one level deep, then set this variable …
valestrom 17 Junior Poster in Training

I'd be using windows vista/7 with Visual C++ 2010

valestrom 17 Junior Poster in Training

I was wondering how to Connect to a FTP server in the form of it having Address, Username, and Password. Then be able to either edit or upload a file to a specific folder on the server. Because I am designing a website with a current news box on it and I would like to be able to not have to use my FTP program every time to change one file.

Summary: Connect to FTP with Address Username Password, and write to a file in a speicifc folder on that server.

Thanks ahead of time

  • Valestrom
valestrom 17 Junior Poster in Training

Hey, I have a volume/surface area calculating program, but the problem is that my program always runs through the first possible choice instead of choosing between two. It will always do the cube/rectangle function instead of going to the square pyramid function.

Here's my code.

#include <iostream>
#include <windows.h>
using namespace std;
char choice[25];
char choice2[25];

int main(){
    system("Color 06");
    cout<<"                 **************************************\n"
          "                 *    Volume/Surface Area Calculator  *\n"
          "                 **************************************\n"
          "                 *                                    *\n"
          "                 *             1: Volume              *\n"
          "                 *             2: Surface Area        *\n"
          "                 *             3: Quit                *\n"
          "                 **************************************\n\n";
          
          cin.getline(choice,25);
          
          if (choice == "1" || "V" || "Volume")
          {
                     system("cls");
    cout<<"                 **************************************\n"
          "                 *    Volume/Surface Area Calculator  *\n"
          "                 **************************************\n"
          "                 *                                    *\n"
          "                 *             1: Cube/Rectangle      *\n"
          "                 *             2: Square Pyramid      *\n"
          "                 *             3: Sphere              *\n"
          "                 **************************************\n\n";
          cin.getline(choice2,25);
          }
          if (choice2 == "1" || "C" || "R" || "rectangle" || "cube")
          {
                     system("cls");
                     int length;
                     int width;
                     int height;
                     int volume;
    cout<<"                 **************************************\n"
          "                 *    Volume/Surface Area Calculator  *\n"
          "                 **************************************\n"
          "                 Enter your the length: ";
          cin>>length;
          cout<<endl<<"                 Enter your the width: ";
          cin>>width; 
          cout<<endl<<"                 Enter your the height: ";
          cin>>height;
          volume=length*width*height;
          cout<<endl<<"                 Volume of your object is: "<<volume;
                                        }
                                        
                                          if (choice2 == "2" || "S" || "P" || "pyramid" || "square")
          {
                     system("cls");
                     int base;
                     int height;
                     int volume;
                     
    cout<<"                 **************************************\n"
          "                 *    Volume/Surface Area Calculator  *\n"
          "                 **************************************\n"
          "                 Enter your the base length: ";
          cin>>base;
          cout<<endl<<"                 Enter your the height: ";
          cin>>height;
          volume=base*base*height*1/3;
          cout<<endl<<"                 Volume of your object …
valestrom 17 Junior Poster in Training

Couple of points.

1) Remove char arrays and use std::string.
2) Looking at the problem you can see that every different enemy will have different stats but in general will have same functions(i.e attack defend ), hence this suggest to create a polymorphic behavior. So I would suggest to do something like so,

//using struct for demonstration
enum EnemyType{ ARCHER, GOBLIN };
struct IEnemy{
 virtual void attack(IEnemy& opponent);
 virtual void takeDamage(int damageToTake); 
 virtual void getHealth();
 virtual void getPower();
 bool isDead()const{ return getHealth() <= 0; }
 EnemyType getType()const;
 virtual IEnemy() {}
};
struct Archer : IEnemy{
 int health;
 int power;
 
 Archer(): health(100) , power(10){}
 int getHealth()const{ return health; }
 int getPower()const{ return power; }
 EnemyType getType()const{ return ARCHER; }

 void attack(IEnemy& opponent){
     opponent.takeDamage( power ); //assume Archer give 10 points of damage
 }
 void takeDamage(int damageToTake){
    health -= damageToTake;
 }

}

//..and so on for other enemies
//..and go on from there

This looks great! Thanks man!

valestrom 17 Junior Poster in Training

Hi, I'm trying to make a set of monsters that have values that can be loaded. Like a Goblin having enemyhealth = 50, enemydamage = 15, etc. Here's what I kinda have an idea of doing... But I really have no idea how to use it.

(File containing values for enemies)
Monsterreader:

#include <iosteam>
using namespace std;

struct Archer {
       char enemyname[25] = "Archer";
  int enemyhealth = 55;
int enemydamage = 15;
int enemydefense = 5;
} ;
struct Goblin {
       char enemyname[25] = "Goblin";
  int enemyhealth = 30;
int enemydamage = 13;
int enemydefense = 10;
} ;

And the actual battle function:

// <strong class="highlight">include</strong> the declaration
#include "battle.h"
#include <iostream>
#include <windows.h>
char battlechoice[10];
char enemyname[25];
char name[50];
int enemyhealth;
int enemydamage;
int enemydefense;
int strength;
 int intelligence;
 int dexterity;
 int health;
 int mana;
 int damage;
 int defense;
 int hitchance;
int roll;
int rollcalc;
int rollcalchit;
int hitroll;
int rand_0toN1(int rollcalc);
int randd_0toN1(int rollcalchit);
using namespace std;

// Function definition



void battleFunction() {
     system("Color 05");
     
     
     srand(time(NULL));
 

     
     system("Cls");
  std::cout << "Battle Initiated";   
  Sleep(2500);
  system("Cls");
  // 17
  std::cout << " _________________       _________________ " << endl;
  std::cout << "|     Battle      |         " << enemyname << endl;
  std::cout << "|-----------------|      _________________ " << endl;
  std::cout << "|     Attack      |                "  <<endl;
  std::cout << "|     Skill       |        Health  " << enemyhealth  <<endl;
  std::cout << "|     Defend      |        Defense " << enemydefense << endl;
  std::cout << "|     Item        |        Attack  " << enemydamage << endl;
  std::cout << "|     Run …
valestrom 17 Junior Poster in Training

I want to be able to launch a program using the system command that is located in the same directory as my program, is there an easy way to do this, without having use the getpath function and store it under a variable? Thanks

valestrom 17 Junior Poster in Training

Your operations are out of order. Create a dialog object, initialize it, then show it:

Info^ form = nullptr;

try {
    form = gcnew Info();

    form->name->Text = "Calculator";
    form->infobox->Text = "Test";

    form->ShowDialog();
} finally {
    if (form != nullptr)
        form.Dispose();
}

This process makes the most sense from a code perspective, but it's especially important with ShowDialog(). From MSDN's page on Form.ShowDialog():

Thanks Narue. Didn't quite pick up on this. But I completely understand what you mean.

valestrom 17 Junior Poster in Training

Okay, so almost the exact same code works in one of my c++/cli projects, but not the other. Both have the variables set as public, so they should be free to change. But only the first one does, and the second one does nothing.
Here's the button click code for the first.

1:

private: System::Void helium_Click(System::Object^  sender, System::EventArgs^  e) {
			   Form2^ form = gcnew Form2();
            form->Show();
			form->atomname->Text = "Helium";
			form->comionic->Text = "N/A";
			form->molmass->Text = "4.00 G/Mol";
			form->atomicnumber->Text = "2";
			form->color->Text = "Colorless";
			form->diatomic->Text = "Yes";
			form->pronounce->Text = "HEE-lee-am";
			form->mpoint->Text = "-272.20 °C";
			form->bpoint->Text = "-268.93 °C";
			form->tpoint->Text = "No Triple Point";
			form->state->Text = "Gas";
			form->adinfo->Text = "Helium naturally occurs as He2. It is a colorless, odorless gas. Helium has no"
				" common compounds, as any compounds made with Helium are extremely unstable at room temperature."
				" Uses include coolant in superconducting magnets, and since it is lighter than air, it is used"
				" to lift airships and balloons, it is also a vital component in rocket fuel.";
				
		 }

And the one that doesn't work.


2:

Info^ form = gcnew Info();
form->ShowDialog();
form->name->Text = "Calculator";
form->infobox->Text = "Test";

It just doesn't change the text at all. Any help? I can't see what I did wrong.

valestrom 17 Junior Poster in Training

I kinda want to code in binary just for the fun of it. But I have no idea how to compile my code. Anyone know how?

valestrom 17 Junior Poster in Training

It's based on the type of the variable. They each have their limits.

I tried both var, and long. I'm not sure what variable is higher than that.

valestrom 17 Junior Poster in Training

it can go as high as you need it to go.

Then why does it hit negative?

valestrom 17 Junior Poster in Training

Just wondering, how high can c++ really count? Because I made a fibonacci program, and it starts acting weird and printing negatives at about 10-11 places. With both long, and int variables? Is it impossible to count higher? If not, how?

valestrom 17 Junior Poster in Training

How many times do I have to repeat myself? You must write the constructor that is being called.

Still have no idea about how to do it, but you gave me enough info that google should be my friend.

Narue commented: Kudos for not expecting everything to be done for you. :) +17
valestrom 17 Junior Poster in Training

My exact code was incomplete. So if you didn't also add a corresponding constructor, my guess was correct.

I was in a hurry, I got your reply and tried it right off, sorry. What part of it is incomplete.

valestrom 17 Junior Poster in Training

You didn't provide any code, so I can only guess that you failed to actually write the constructor.

I copied your exact code.

valestrom 17 Junior Poster in Training

Define your own constructor for Form2 that accepts this information and sets control values accordingly. For example:

Form2^ frm = gcnew Form2("Hydrogen");

frm->ShowDialog();

This didn't work. Upon entering this exactly I got:

1>c:\users\blackmethod\documents\visual studio 2010\projects\valestrom's periodic table\valestrom's periodic table\Form1.h(2086): error C3673: 'ValestromsPeriodicTable::Form2' : class does not have a copy-constructor


Help on what's wrong here?

valestrom 17 Junior Poster in Training

Eh, it's aight. I'll just install visual studio and take the shit when it comes. Thanks anyway.

valestrom 17 Junior Poster in Training

Because I need to have it portable. Because at school they use some god awful virtual desktop, and it doesn't allow me to install on a virtual drive. =/


I would love to use it if I could.

valestrom 17 Junior Poster in Training

Hey, I was just wondering how I can get it so when I click a button it opens my second form. But sets some of the labels to a specific thing, so I don't end up making 170+ forms for my periodic table application. Just like so when I click "H" it opens the "Form2" and sets the label "atomname" to "Hydrogen"?

Here's my buttonclick so far.

private: System::Void hydrogen_Click(System::Object^  sender, System::EventArgs^  e) {
				 Form2^ newform2 = gcnew Form2;
				 newform2->ShowDialog();
valestrom 17 Junior Poster in Training

Hey, I'm looking for an IDE with .NET capabilities, but not visual studio. As I need it to run off a flash drive. Any suggestions?

valestrom 17 Junior Poster in Training

Nobody?

valestrom 17 Junior Poster in Training

So I'm making this periodic table application, and spent an hour laying it all out. Perfectly I must add. Now I'm trying to figure out how to get it so when I click a button it opens the new form (Have this done) and replace the value of some labels/textboxes etc. How would I go about this? Here's my button clicked script.

private: System::Void hydrogen_Click(System::Object^  sender, System::EventArgs^  e) {
				 Form2^ newform2 = gcnew Form2;
				 newform2->ShowDialog();

What I would like to be able to get is so on click it opens the form, and sets the value of "atomname" to "Hydrogen". Thanks ahead of time guys!

valestrom 17 Junior Poster in Training

I have multiple errors in my code that I was just working on, the errors are as follows:

Here is my build log:


monsters.h:11: error: storage class specified for field `enemyattack'
monsters.h:11: error: ISO C++ forbids initialization of member `enemyattack'
monsters.h:11: error: making `enemyattack' static
monsters.h:11: error: ISO C++ forbids in-class initialization of non-const static member `enemyattack'
monsters.h:12: error: storage class specified for field `enemyhealth'
monsters.h:12: error: ISO C++ forbids initialization of member `enemyhealth'
monsters.h:12: error: making `enemyhealth' static
monsters.h:12: error: ISO C++ forbids in-class initialization of non-const static member `enemyhealth'
monsters.h:13: error: storage class specified for field `enemydefense'
monsters.h:13: error: ISO C++ forbids initialization of member `enemydefense'
monsters.h:13: error: making `enemydefense' static
monsters.h:13: error: ISO C++ forbids in-class initialization of non-const static member `enemydefense'
monsters.h:14: error: missing terminating ' character
monsters.h:15: error: expected primary-expression before '}' token
monsters.h:15: error: storage class specified for field `enemy'
monsters.h:15: error: ISO C++ forbids initialization of member `enemy'
monsters.h:15: error: making `enemy' static
monsters.h:15: error: ISO C++ forbids in-class initialization of non-const static member `enemy'
monsters.h:15: error: expected `;' before '}' token
monsters.h:15: error: expected `;' before '}' token

main.cpp: In function `int main()':
main.cpp:14: error: `enemyhealth' undeclared (first use this function)
main.cpp:14: error: (Each undeclared identifier is reported only once for each function it appears in.)

main.cpp:15: error: `enemyattack' undeclared (first use this function)

valestrom 17 Junior Poster in Training

Title pretty much sums it up. All I want it to do is be able to compare the text from two char variables. So here's my code:

#include <iostream>
#include <windows.h>
using namespace std;

int main() {
    system("color 04");
    char symbol[100];
    char answer[100];
    int i;
    i = 1;
    cout <<"Enter a symbol or line of text: ";
    cin.getline(symbol, 100);
    for (i=1; i<100000; i++){
    cout << symbol;
}
system("cls");
cout <<"What did it say?";
cin.getline(answer, 100);
if (answer == symbol)
{
           cout <<"\nYou won!";
           Sleep(5000);
           }
           else
           cout << "You suck.";
    
  
    
    return 0;
}
valestrom 17 Junior Poster in Training

1. For C++, use endl manipulator instead of \n for newlines.
2. The shutdown command has to run as root.
3. There is no loop here, so it should not start over, unless you named your program "shutdown"...

What do you mean by as a root?
I had the same line of code being the system shutdown part and it worked before, can you give an example?


Nevermind got it working. Just had to change the name... Lol.

valestrom 17 Junior Poster in Training

My program is in an infinite loop, when It hits the "Bye" part in the code it goes right back up to the top. Help with this. It's a pretty simple program so I can't see what I did wrong.

#include <iostream>
#include <windows.h>

using namespace std;

int main () {
    cout<<"Shutdown sequences initiated! \n";
    cout<<"3";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<"2";
    cout<<".";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<"1";
    cout<<".";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<".";
    Sleep(250);
    cout<<"Bye!";
    system("shutdown -s");
    
    

return 0;
}
valestrom 17 Junior Poster in Training

I presume that you intend the function named Gcffunction to accept two int values and return an int that is the greatest common factor. Your function is a recursive function, which calls itself over and over until the answer is reached, but you've made a simple typo in it.

As it is, your function looks a little wobbly. Here is a working function that accepts two integers and returns an integer that is the greatest common factor.

int Gcffunction(int a, int b)
{
	if(b == 0)
	{
	        return a;
	}
	else
	{
		return Gcffunction(b, a % b);
	}
}

You can see that it's very similar to your original Gcffunction, but this one now calls itself recusrsively (you wrote return gcf(gcf2, gcf1 % gcf2); where I think you should have written return Gcffunction(gcf2, gcf1 % gcf2);)

This function needs to be passed the two values, and returns an int. I note that your original function didn't get passed the values, but instead took them from the class in which it lives, and your code seems a little confused about whether the Gcffunction returns anything (the function returns void i.e. there is no return, but them you try to return something anyway) so you need to decide exactly what you want the inputs and outputs to be.

Hope that's clear now - it was a simple typo and now that I've rambled on about it I hope you've got enough to fix it all.

Excited to try this out, thanks!

valestrom 17 Junior Poster in Training

Please tell me what you're attempting to do, because from looking at that, it appears you're attempting to call a function that has been stored as a pointer into the int variable (ints can store pointers and be used as function pointers but in most cases this is a bad idea) There's really no .net equivalent, so I'm not sure what you're trying.

Explain what you want this line to do and I will show you how to do it :)

I'm trying to get the input from the user from the two text boxes, then use a function to calculate the GCF (or Greatest Common Factor) of those two numbers. I'm not sure how to do this in .NET, I swiped this code from my console c++ book, but I couldn't find a solution to get it to work with this program.

In summary:
Get input from 2 boxes gcf1 and gcf2, calculate the GCF, then store in under the integer variable gcf

valestrom 17 Junior Poster in Training

I concur, the error I see is return gcf(gcf2, gcf1 % gcf2); I can't really work out what you're trying to do with this line eitherin context of your application. The only thing I can think of, is that you're trying to use gcf as a pointer to some method, but this is an incredibly bad way to do things, in my opinion.

I kinda got lost on how to do it. This whole function, and yes line 76 was the return gcf line. That code is how it showed up in my c++ book, but I haven't figured out how to port the same code/idea to .NET

valestrom 17 Junior Poster in Training

Hi, I got the error
C2064: term does not evaluate to a function taking 2 arguments
The error is in line 76, help would be great.

Here is my code:

#pragma once



namespace ValestromsCalculator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for GCF
	/// </summary>
	public ref class GCF : public System::Windows::Forms::Form
	{
	public:
		GCF(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~GCF()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  textBox1;

	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;

	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Button^  button2;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;
		// My Variables
	private:
		int gcf1;
		int gcf2;
		int gcf;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void Gcffunction() {
			if (gcf1 % gcf2 == 0){
				gcf = gcf2;
			}
			else{
				return gcf(gcf2, gcf1 % gcf2);
			
			}
		}

		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(100, 36);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(39, 20);
			this->textBox1->TabIndex …
valestrom 17 Junior Poster in Training

It's not straight C++. This operator that you're using alot: ^, in C++ is only the bitwise XOR operator. In your code above, it carries a different meaning.

gcnew is a variant on new that adds garbage collection - straight C++ has no built-in garbage collection.

There are other clues too, but the crux of it is that you're not coding in straight C++. You're not the first be coding in C++/CLI and not realise it :)

That said, we can probably still help you, but we'd rather not wade through all your code in search of the error; presumably your error message indicates which line is erroneous?

Sorry, thought I included that. Line 76
error C2064: term does not evaluate to a function taking 2 arguments

valestrom 17 Junior Poster in Training

Yeah you should post in the C# forum because C++/CLI uses .NET
People like "Moschops" don't even know what C++/CLI is.

Sarcasm? I hope. Cause this is c++

valestrom 17 Junior Poster in Training

Hopefully my last question for awhile, I wrote a piece of code like this before, but now I get the error:
error C2064: term does not evaluate to a function taking 2 arguments

Here is my code:

#pragma once



namespace ValestromsCalculator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for GCF
	/// </summary>
	public ref class GCF : public System::Windows::Forms::Form
	{
	public:
		GCF(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~GCF()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  textBox1;

	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;

	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Button^  button2;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;
		// My Variables
	private:
		int gcf1;
		int gcf2;
		int gcf;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void Gcffunction() {
			if (gcf1 % gcf2 == 0){
				gcf = gcf2;
			}
			else{
				return gcf(gcf2, gcf1 % gcf2);
			
			}
		}

		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->textBox3 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->button2 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(100, 36);
			this->textBox1->Name = …
valestrom 17 Junior Poster in Training

So, that did work. But now is there a way that I could make it possible to work like I had it?