14 Replies - 745 Views - Last Post: 21 October 2009 - 05:27 AM Rate Topic: -----

#1 gringo88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-October 09

Help with a homework, basic stuff :)

Post icon  Posted 20 October 2009 - 11:04 AM

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace zadatak1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			Text4.Text = Convert.(Convert.ToDouble(Text1.Text) + Convert.ToDouble(Text2.Text) + Convert.ToDouble(Text3.Text));
			

			
			Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text);
			Convert.ToString(Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text) );
			
		}
		
		
	}
} 


Ok guys there it is. Please help me with my homework. The problem is this part of the code:
Text4.Text = Convert.(Convert.ToDouble(Text1.Text) + Convert.ToDouble(Text2.Text) + Convert.ToDouble(Text3.Text))
, identifier expected error at Text4.Text = Convert.( , with ( being underlined as problem

This post has been edited by gringo88: 20 October 2009 - 11:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help with a homework, basic stuff :)

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:10 AM

is that C# it looks like to me

so this must be

Text4.Text = Convert.ToString(Convert.ToDouble(Text1.Text) + Convert.ToDouble(Text2.Text) + Convert.ToDouble(Text3.Text))



you forget Text4.Text = Convert.ToString( ... );

This post has been edited by NoBrain: 20 October 2009 - 11:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 gringo88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-October 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:13 AM

Its a Visual C#. I'm really sorry if i got mixed up and posted in the wrong section. I'm new to programing.
Was This Post Helpful? 0
  • +
  • -

#4 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:17 AM

no problem i edit my post check if that is what your looking for. Pls dont make second in C# forum. I will report it to be moved :)

This post has been edited by NoBrain: 20 October 2009 - 11:18 AM

Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:19 AM

Moved to C# :)
Was This Post Helpful? 0
  • +
  • -

#6 gringo88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-October 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:22 AM

NoBrain, yeah that helped but i have another error now:
Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text);


Only assignment, call, increment, decrement ,and new object expressions can be used as statements
Was This Post Helpful? 0
  • +
  • -

#7 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:26 AM

hi :)

well that row is useless i mean you have to make something with it Print it give it to some variable to store it or display it in text box for Example:

SomeVarInt=Convert.ToInt16(Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text));



in short Convert.ToInt16() function return Intiger value to the Expression you give to that function

good luck :)

This post has been edited by NoBrain: 20 October 2009 - 11:28 AM

Was This Post Helpful? 0
  • +
  • -

#8 gringo88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-October 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:30 AM

Oh man, haven't noticed that. The little program isn't over yet, i have to make another few rows, so i will see if everything will work. If it doesn't i will be back here, so mods please don't trash the thread yet.

NoBrain, thanks again :)
Was This Post Helpful? 0
  • +
  • -

#9 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 11:34 AM

no problem :)
Was This Post Helpful? 0
  • +
  • -

#10 gringo88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-October 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 12:00 PM

Ok here it is, program how it should work on paper:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace zadatak1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			text4.Text = Convert.ToString(Convert.ToDouble(Text1.Text) + Convert.ToDouble(Text2.Text) + Convert.ToDouble(Text3.Text));

			Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text); 
			Convert.ToString(Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text) );
			
			

		}

		private void Form1_Load(object sender, EventArgs e)
		{
			MessageBox.Show("Program izračunava prosječnu ocjenu.", "zadatak1",
			MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
		}
		
		
	}
}



This is how the teacher explained it to do. The program is supposed to work, like you write 3 numbers (hence the 3 text boxes), and in forth and final box, it calculates arithmetic middle. It just divides the numbers.

I really don't understand what to do with
Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text); 


I don't know which variable i should save it to, as teacher explained it so poorly. Everything except that seems fine. The part written in MessageBox i know it isn't on english, but it is just a text that pops out after calculation is over, nothing important for codes :) .
Was This Post Helpful? 0
  • +
  • -

#11 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 12:52 PM

so you want to pop up messages?
Was This Post Helpful? 0
  • +
  • -

#12 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 01:19 PM

your problem (again) is that you are not assigning the result of the addition to a variable.

see the different between this..
someVar = 1 + 2;



and ...
1 + 2;



the second is not a valid statement in c#. You must assign the value.
Was This Post Helpful? 0
  • +
  • -

#13 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Help with a homework, basic stuff :)

Posted 20 October 2009 - 01:24 PM

so you could do something like..

int sum = Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text);



so now you have a variable that contains the value of all of the integers added together. I will let you try to finish and determine the middle.
Was This Post Helpful? 0
  • +
  • -

#14 gringo88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-October 09

Re: Help with a homework, basic stuff :)

Posted 21 October 2009 - 03:57 AM

Ok guys, you were really helpful, and things you explained to me worked.

text4.Text = Convert.ToString(Convert.ToDouble(Text1.Text) + Convert.ToDouble(Text2.Text) + Convert.ToDouble(Text3.Text));

			text4.Text = Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text);
			Convert.ToString(Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text) );


I got this error now at second row. Cannot implicitly convert type int to string.

I know it's something really trivial, but i'm a complete beginner at this.

This post has been edited by gringo88: 21 October 2009 - 04:08 AM

Was This Post Helpful? 0
  • +
  • -

#15 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Help with a homework, basic stuff :)

Posted 21 October 2009 - 05:27 AM

this code is the problem...

text4.Text = Convert.ToInt16(Text1.Text) + Convert.ToInt16(Text2.Text) + Convert.ToInt16(Text3.Text);



as you can see, you are adding integers, which will return an integer. You are then trying to assign that integer value to the .Text property of the textbox. The Text property is a string. So you are trying to assign an integer value to a string. C# doesn't allow this. You must convert the value to a string.

Do it exactly like you did the first line in the code. In that line, you convert the added doubles to a string then assign it to the Text property.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1