none
Problem Open - error C4700: uninitialized local variable 'dochod' used

    Question

  • 1>c:\users\user\documents\visual studio 2013\projects\dochod\dochod\dochod.cpp(15): error C4700: uninitialized local variable 'dochod' used

    // dochod.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
    	double dochod;
    
    	int prog;
    	if (dochod <=3089) prog = 0;
    	else
    	if (dochod <85528) prog = 1;
    	else
    	prog = 2;
    
    	cout << "Podaj swoj miesieczny dochod w zlotowkach: ";
    	cin >> dochod;
    
    	switch (prog)
    	{
    	case '0':
    		cout << "Podatek za miesiac, ktory musisz zaplacic to " << dochod * 0 << " zlotych.";
    		cout << "Rocznie daje to " << dochod * 0 * 12 << " zlotych.";
    		break;
    	case '1':
    		cout << "Podatek za miesiac, ktory musisz zaplacic to " << dochod * 0.32 << " zlotych.";
    		cout << "Rocznie daje to " << dochod * 0.32 * 12 << " zlotych."; \
    			break;
    	case '2':
    		cout << "Podatek za miesiac, ktory musisz zaplacic to " << dochod * 0.18 << " zlotych.";
    		cout << "Rocznie daje to " << dochod * 0.18 * 12 << " zlotych.";
    		break;
    	}
    
    	cout << "Nacisnij dowolny klawisz.";
    	return 0;
    }
    
    

    Wednesday, December 04, 2013 1:25 PM

Answers

  • 1>c:\users\user\documents\visual studio 2013\projects\dochod\dochod\dochod.cpp(15): error C4700: uninitialized local variable 'dochod' used

    Good, the error is telling you exactly what the problem is.

    int main()
    {
       double dochod;
       int prog;
       if (dochod <=3089) prog = 0;

    What do you think dochod contains at that point?

    Dave

    Wednesday, December 04, 2013 2:26 PM
  • Hi Exactlyx,

    Your error tells that you need to initialize "dochod" before you use it. In your code, you compare dochod with 3089 and compare dochod with 85528 but without initializing any vuale in dochod.

    Friday, December 06, 2013 10:00 AM

All replies

  • 1>c:\users\user\documents\visual studio 2013\projects\dochod\dochod\dochod.cpp(15): error C4700: uninitialized local variable 'dochod' used

    Good, the error is telling you exactly what the problem is.

    int main()
    {
       double dochod;
       int prog;
       if (dochod <=3089) prog = 0;

    What do you think dochod contains at that point?

    Dave

    Wednesday, December 04, 2013 2:26 PM
  • Hi Exactlyx,

    Your error tells that you need to initialize "dochod" before you use it. In your code, you compare dochod with 3089 and compare dochod with 85528 but without initializing any vuale in dochod.

    Friday, December 06, 2013 10:00 AM