Visual Net Pay, Gross, & Withholding %
Hello everyone! I'm new to visual basic... I'm currently having problems with coding this program that my teach had me do. Can anyone check the coding and see what I have done wrong? Each time I tried to build solutions error messages pop up, and the build is unsuccessful, here's the coding.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Anon_Ch3Project
{
class Program
{
static void Main(string[] args)
{
int num1;
int num2;
int num3;
int gross;
int net;
int witholding;
int sum;
Console.Write("How many hours have you worked? "); //# of hours worked
num1 = Convert.ToInt32(Console.ReadLine()); //
Console.Write("How much are you paid per hour? "); // What's your pay rate?
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("What's your witholding percentage: "); //# Witholding
num3 = Convert.ToInt32(Console.ReadLine()); //
sum = num1 * num2;
Console.WriteLine("The Gross Pay is : {0} ", gross);
sum = gross + num3;
Console.WriteLine("The Net Pay is : {0} ", net);
sum = gross * num3;
Console.WriteLine("The Withholding is : {0} ", witholding);
}
}
}
[The project should display a title (whatever you choose for the title). The program will prompt the user for 3 things;
* Number of hours worked
* Their pay rate
* Withholding percentage
Your program will then display 3 things
* Their gross pay
* The withholding amount
* The net pay]
If anyone could help, that'd be awesome. :afrog:
Re: Visual Net Pay, Gross, & Withholding %
Thread moved from the 'CodeBank VB.Net' forum (which is for you to post working code examples, not questions) to the 'C#' forum
Re: Visual Net Pay, Gross, & Withholding %
So what's the problem? We're not mind readers. If you're getting errors, what are they?
-tg
Re: Visual Net Pay, Gross, & Withholding %
Welcome!!! :wave:
Please use code tags when entering code. It makes it much easier to read.
I see problems with your formulas:
Code:
sum = num1 * num2;
Console.WriteLine("The Gross Pay is : {0} ", gross);
You're printing gross but never assiging it a value. You are assigning a value to sum but not doing anything with it. Look over your formulas and see if you can fix them. Ask questions and we will answer them, but you may be able to fix it yourself now that I gave you a hint.
Re: Visual Net Pay, Gross, & Withholding %
You're getting errors when you try and use the three variables 'gross', 'net' and 'witholding' in the Console.WriteLine statements and the gross variable in the second and third assignments to sum. Look at the errors:
"Use of unassigned local variable 'xxx'"
What does this error suggest? It's saying that you're attempting to use a variable that has not been assigned. How to resolve this error? Assigning a value to the variable would be a logical thing to try. What value should you assign?
Re: Visual Net Pay, Gross, & Withholding %
Well, I'm not getting errors but it's calculating incorrectly. I'm trying to figure out why it's doing that. The build is succeeding. I'm looking over the coding now.
Re: Visual Net Pay, Gross, & Withholding %
Did you read my post? It explains where the problem is.
Re: Visual Net Pay, Gross, & Withholding %
Yes, I had read it. Thank a lot, guys! :D I managed to create it.
Re: Visual Net Pay, Gross, & Withholding %
Woot. Hopefully you learned from it too.