new to c++, and prof. assigned to write a business card style program, my codes are below, but it says variable "rate" and "hour" are not initialized, and it seems theres something wrong with the getline(cin string), please use simple codes and explain.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
double payroll;
double rate; //says being used without being initialized
double hour; //also says being used without being initialized
payroll = hour * rate;
string addr;
string city;
string state;
string zipcode;
string first;
string last;
string title;
string company;
cout <<"Please Enter Your Personal Information Below to Generate Your Business Card..."<<endl;
cout << "First Name: ";
cin >> first;
cout << "Last Name: ";
cin >> last;
cout << "Job Title: "; //this line doesn't break to a new line
getline(cin,title);
cout << "Company Name: "; // it shows like Job Title: Company Name:
getline(cin,company);
cout << "Door Number and Street Name: ";
getline (cin, addr);
cout << "City: ";
getline(cin,city);
cout << "State: ";
getline(cin,state);
cout << "Zip Code: ";
cin >> zipcode;
cout << "Hourly Paid Rate in Dollar: ";
cin >> rate;
cout << "Hours Worked: ";
cin >> hour;
cout <<"You Entered..." <<endl;
cout <<"==============================================" <<endl;
cout << first << " " << last << endl; // I want to make this line show in uppercase
cout << title <<" of " << company <<endl; // This line in uppercase also
cout << addr << endl;
cout << city << " " << state << " " << zipcode << endl;
cout << "Your payroll is: " << payroll <<endl;
system("pause");
return 0;
}
Look at line 11. What is currently inside of hour, and what is currently inside of rate? Remember- the code is being completed a bit like a list. Payroll isn't being "defined" as the product of the two for every instance of those being updated, but rather is being defined as such for the instance of hour and rate at the beginning of the code.
Add this after line 3. #include <ctype.h> // for toupper(int)
Add this before main function.
1 2 3 4 5 6 7
// Change each character in str to an upper character. Return the new str.
std::string Upperify(std::string str) {
for(unsigned counter = 0; counter < str.length(); counter++) {
str[counter] = toupper(str[counter]);
}
return str;
}
and now everything is seem to be working well.
and just being curious, do i have to do it like shown above one by one ? or is there a way to do it all together ? for the "first","last","title", and "company" ?