Error 1 error C4700: uninitialized local variable 'rate' and 'hours' in C++

uninitialized local variable used struct
we4700
uninitialized local variable char
msvc uninitialized variable warning

I am a beginner to programming. I'm writing a C++ program that a user will their pay rate and the hours worked, and then calculate the pay and hours worked then display it. I finish the program the there are two errors that I tried to fix but I still can't figure out to fix it. The errors and my code is below. Can someone help me and tell me how to fix? I'm using MSVS Express 2013.

Errors:

Error   1   error C4700: uninitialized local variable 'hours'

Error   2   error C4700: uninitialized local variable 'rate'

(It is erroring on displayWeekly(rate, hours);)

My Code:

#include "stdafx.h"

#include<iostream>

using namespace std;
void displayWeekly(double rate, int hours);
double getRate();
int getHours();

int main()
{

double rate; 

int hours;

displayWeekly(rate, hours);

double getRate();
int getHours();

rate = getRate();
hours = getHours();

system("pause");
return 0;
}

void displayWeekly(double rate, int hours)
{
double weekPay;
weekPay = rate * hours;
cout << "Weekly pay is " << weekPay << endl;
}

double getRate()
{
double rate;
cout << "Enter your Hourly rate in the Dollars and Cents = ";
cin >> rate;
return rate;
}

int getHours()
{
int time;
cout << "Please Enter in the Hours you worked" << endl;
cout << "You must Enter a whole Number = ";
cin >> time;
return time;
}

Your new main should look something like this:

int main()
{
    double rate;
    int hours;

    //double getRate(); --> where do you think the return value is stored to?
    //int getHours();   --> 

    rate = getRate();
    hours = getHours();

    displayWeekly(rate, hours);  // --> has to go after you put values to rate & hours

    system("pause");
    return 0;
}

Error 1 error C4700: uninitialized local variable 'rate' and 'hours' in , Your new main should look something like this: int main() { double rate; int hours; //double getRate(); --> where do you think the return value is  Inside the print () function are two local variables with the same name currPtr where the first is unitialized. This can be easy found using the search option of your editor to check all occurences of the variable name. The error message contains also a line number where the error occurs. With your error this might be the last line of the function where the variable is defined.

You pass uninitialized variables to displayWeekly ,multiply them and print them which causes the error. Instead,call that function after you call getHours and getRate so that they get initialized.

Also

double getRate(); 
int getHours();

In main are unecessary.Remove them.

getting error C4700: uninitialized local - C++ Forum, My issue is i am getting error C4700: uninitialized local variable 1) have the user enter 20 answers from an exam taker and write the answers  only declares the variable, it doesn't initialize it. C++ doesn't initialize local variables for you. So when the code gets to this line: while (toupper(choice) != 'E') it reads an uninitialized variable. This is undefined behavior. VS is detecting the problem and is telling you about it.

Here the main mistake that you have done is ignoring the order (flow ) of your code .

int main()
{

double rate; 

int hours;

displayWeekly(rate, hours);//-> this is the func call that lead to error,cozz the arguments rate,hours are not still initialized .You calculated them after the function call.

double getRate();
int getHours();

rate = getRate();
hours = getHours();
                   //->it helps if you call display func here.
system("pause");
return 0;
}

c++ error: warning C4700: uninitialized local variable 'k' used, can anyone tell me what's the problem here? warning C4700: uninitialized local variable 'k' used #include <iostream> #include <vector> Error 1 error C4700: uninitialized local variable 'rate' and 'hours' in C++ - Stack Overflow. I am a beginner to programming. I'm writing a C++ program that a user will their pay rate and the hours worked, and then calculate the pay and hours worked then display it. I finish the program the Stack Overflow.

[C++] Error C4700: uninitialized local variable 'choice' used (Visual , [C++] Error C4700: uninitialized local variable 'choice' used (Visual Studio) [I'll study high-school math during steps 0 and 1, but to keep it simple, I've put it  Uninitialized variables are not initialized to random values, they are uninitialized. On a machine code level, they have whatever value was there when they were created. This may or may not be the address of an actual object. Either way, it is undefined behavior to try to access an uninitialized pointer value as if there is an object at that address.

[Solved] error C4700: uninitialized local variable 'currPtr' used , Inside the print() function are two local variables with the same name currPtr where the first is unitialized. This can be easy found using the  So you use the variable j first in the line. f1 = FormAry[j].Element1; But you haven't assigned any value to j previously, hence "uninitialized". The previous mention of j was in your declaration:

Uninitialized local variable tc used ( error), The error message is very explicit: Hide Copy Code. Uninitialized local variable tc used. A quick glance at your code confirms this: Hide Copy  We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge. Sign Up — It's Free! Related Topics

Comments
  • What do you expect the value of hours to be when you pass it to displayWeekly? You didn't initialize it so it has an undefined value.
  • Didn't I initialize by inputting in the parenthesis rate and hour, or that not it whats by initializing?
  • No. You declare them at the beginning of your main function but give them no value. What do you think the value of hours will be?
  • I am referring you to this post stackoverflow.com/questions/21917424/… , you need to initialize pointer .
  • Thank you it work just fine. Guess it just the positioning on where I place it.