C++ please help

Hello, I'm new to doing and I'm taking a course I can't find out what is wrong with this code.

Could someone please help me?

 

//FILE:Lab1.cpp
//PROGRAMMER: Skreedles
//PURPOSE: Displays a User's nickname and hours worked
#include <iostream> //for cin and count
#include <iomanip> //for formatting decimal numbers
#include <string> //for using the string class
using namespace std; //for later versions of C++
int main ()
{
//Local data...
char letter1, letter2, letter3; //input: three letters to display
double hoursPerDay, hoursPerWeek; //hours per day, hours per week
int numDays; //number of days worked in a week
string name; //user's first name
//Enter name and initials, the hours per day
//and the number of days
cout<<"Please enter your name";
cin>> name;
cout<<"Enter three initials for your name:";
cin>>letter1>>letter2>>letter3;
cout<<"Enter the number of hours you work in a day: ";
cin>>hoursPerDay;
cout<<"Enter the number of Days you work in a week: ";
cin>>numDays;
//Calculate the number of hours worked in a week
hoursPerWeek=hoursPerDay * numDays;
//Output a messageformatting the hours to one decimal place
cout<< fixed << showpoint << setprecision(1);
cout<<"Hello" <<name <<endl;
cout<<"Your intitials are: " <<letter1 <<"."
<<letter2<<"."<<letter3 <<".\n";
cout<<"I hope you enjoy studying C++ for" <<hoursPerWeek
<<"hours each week!" <<endl<<endl;
cout<<"Written by Skreedles"
<<endl;
return 0;
}

what do you mean whats wrong with it? Usually the compiler will point to the line that has an issue.

Do you mean that the program exits before you have time to see the outputs you're printing?

Try adding the following just before the return statement (if you're compiling / running this on Windows-- I'm not sure what the equivalent would be in Linux / Mac OS): 

system("pause"); 

Hopefully this works, my C++ knowledge is quite limited.

 

A more friendly and possibly platform-neutral way would be to simply do the following:

std::cout << "Press enter to exit: " << endl;

std::cin.get();  // Waits for user input

I also recently purchased a book called C++ Primer. While reading on a few bits, I definitely understood each and every sentence this author wrote. However, I also will concede that I had some sort of C++ experience before hand ( abiet limited ); reading from the starting chapters does make the core concepts easier to digest. If you're having trouble understanding something, you can always play with the code within an IDE such as Eclipse, or Visual Studio.

There ya go, ignore my post.

How about using printf() and scanf() instead of cin and cout?

cin/cout is how C++ is taught in most schools.

What IDE are you using? aside from a few endl's or "\n"s the code looked fine to me running in codeblocks.

//FILE:Lab1.cpp


//PROGRAMMER: Skreedles


//PURPOSE: Displays a User's nickname and hours worked


#include <iostream> //for cin and count


#include <iomanip> //for formatting decimal numbers


#include <string> //for using the string class


using namespace std; //for later versions of C++


int main ()
{
//Local data...


char letter1, letter2, letter3; //input: three letters to display


double hoursPerDay, hoursPerWeek; //hours per day, hours per week


int numDays; //number of days worked in a week


string name; //user's first name


//Enter name and initials, the hours per day


//and the number of days


cout<<"Please enter your name\n";


cin>> name;


cout<<"Enter three initials for your name:\n";


cin>>letter1>>letter2>>letter3;


cout<<"Enter the number of hours you work in a day: \n";


cin>>hoursPerDay;


cout<<"Enter the number of Days you work in a week: \n";


cin>>numDays;


//Calculate the number of hours worked in a week


hoursPerWeek=hoursPerDay * numDays;


//Output a messageformatting the hours to one decimal place


cout<< fixed << showpoint << setprecision(1);


cout<<"Hello " <<name <<endl;


cout<<"Your intitials are: " <<letter1 <<"."
<<letter2<<"."<<letter3 <<".\n";


cout<<"I hope you enjoy studying C++ for " <<hoursPerWeek
<<" hours each week!\n" <<endl<<endl;


cout<<"Written by Skreedles"
<<endl;


cin.get();


return 0;


}

Let me know if this works better for you or not.

If it does not, and you're allowed to use it, you could do:

#include <cstdlib>

(all of your code here except the return 0;)

system("pause");

return 0;

But printf/scanf is much, much faster.

Because it matters with less than 100 lines of code =P

This is a CS1 class, nobody is concerned with speed.

Fair enough. Still, if we're considering this in terms of academic education, they should write programs in Pascal (the academic language). It's very easy, there are words instead of characters and it's easy to migrate to C/C++/Java/whatever afterwards.