4 Replies - 915 Views - Last Post: 29 October 2019 - 12:03 PM Rate Topic: -----

#1 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 795
  • Joined: 15-December 14

Re doing the pop machine and I can't get the math to work

Posted 29 October 2019 - 11:47 AM

Started a new job as a python programmer and the new company wants me to learn c#. So I stopped learning C++ to learn c# and I am in the process of re doing some of my old programs I worked on in C++.

I am in the process of redoing the pop machine and I can't figure out why I can't get this to work. In C++ I made a variable type called popchange which was:
int coins, pennies, nickels, dimes, quarters, dollars, fives, tens,
                twenties, fifties, hundreds;
double bottle = 1.55;
double popchange = bottle - coins;


But for some reason I can't do the same thing in C#. I've tried everything I could think of and nothing seems to work. Can I get a hint or a suggestion?

This is the program so far.
using System;

namespace Popmachine
{
    class Program
    {
        static void Main(string[] args)
        {
            int coins, pennies, nickels, dimes, quarters, dollars, fives, tens,
                twenties, fifties, hundreds;
            double money = 0;
            double bottle = 1.55;
            double total = 0;
            double sum = 0;
            string []pop = { "1.Coke", "2.Pepsi", "3.Sprite", "4.Dr Pepper",
                "5.Water", "6.Gadorade\n" };
            double popchange = bottle - money;
            string star = "*";
            int bottlex = 155;
            double change = bottle - coins;
            
        }
    }
}

This post has been edited by albert003: 29 October 2019 - 11:48 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Re doing the pop machine and I can't get the math to work

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,803
  • Joined: 12-June 08

Re: Re doing the pop machine and I can't get the math to work

Posted 29 October 2019 - 11:50 AM

What error message are you seeing?
Was This Post Helpful? 0
  • +
  • -

#3 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 795
  • Joined: 15-December 14

Re: Re doing the pop machine and I can't get the math to work

Posted 29 October 2019 - 11:57 AM

The word coins in highlighted and a little box appears saying this:
Use of unassigned local variable 'coins'
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15427
  • View blog
  • Posts: 61,803
  • Joined: 12-June 08

Re: Re doing the pop machine and I can't get the math to work

Posted 29 October 2019 - 11:58 AM

... so assign it a value. Initialize it.
Was This Post Helpful? 0
  • +
  • -

#5 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 795
  • Joined: 15-December 14

Re: Re doing the pop machine and I can't get the math to work

Posted 29 October 2019 - 12:03 PM

Well duh! Colour me stupid. Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1