codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Help with Easy Prog  pappledoo at 04:42 on Wednesday, March 05, 2008
 

I can't find my error in this:
Here's the problem:
-------------------------------------------------------
You should then leave one blank line and prompt for and accept from the user the "Day of the Week." You are to use single characters to represent each day of the week ('S' 'M' 'T' 'W' 'R' 'F' 'A'). You should display these choices to the user as part of your prompt. Your program should assume the user will only enter uppercase letters for the days of the week; all other characters entered (including the lowercase letters for the days) are to be considered invalid.

Test the value that the user enters and display an appropriate response, using the following algorithm:

if Saturday or Sunday then
write a "Weekend" message, such as: "Hooray!, it's the weekend!"
else
if it's a Weekday then
prompt for and accept the hour of day (0 through 23)
[you can assume the user will enter a valid integer]
if hour is between 8 and 17 inclusive then
write a "should be at work" message
else
if hour is >= 0 and < 8 then
write a "still asleep" message
else
if hour is > 17 and < 24 then
write an "off work" message
else
write an "hour invalid" message
else
write a "day invalid" message

Write the program so that it goes through this sequence only once. If the user would like to enter a new day he must rerun the program.

Please note that the algorithm shown above is not in proper C syntax. It is merely an English-like stating (commonly referred to as pseudocode) of the algorithm to be used for this program. For this pseudocode to work properly in C, you will have to declare the appropriate variables, perform the necessary comparison tests (as indicated) using the proper C if-else-statement syntax, and (where needed due to performing more than one command inside an if statement) properly use blocks.
---------------------------------------------------------------

Here's my code:
/* C++ Program
*/

#include <iostream>

int main() {
int hour = 0;
char day = 'q';

while (day != 'S' && day != 'M' && day != 'T' && day != 'W' && day != 'R' && day != 'F' && day != 'A')
{
cout << "What day is it? << endl << "Please enter your response with a capital letter: S, M, T, W, R, F, or A" << endl;
cin >> day;
if (day != 'S' && day != 'M' && day != 'T' && day != 'W' && day != 'R' && day != 'F' && day != 'A')
cout << "Invalid entry" << endl;
}
if (day == 'S' || day == 'A')
cout << "Enjoy the weekend! Yay!" << endl;
else {
while (hour <= 0 or hour >= 23)
{
cout << "What hour is it?" << endl << "Enter a number between 0 and 23" << endl;
cin >> hour;
if (hour <= 0 or hour >= 23)
cout << "Invalid hour" << endl;
}
if (hour >= 8 && hour <= 17)
cout << "You should be working! Get back to work!" << endl;
if (hour >= 0 && hour <= 8)
cout << "Go back to sleep!" << endl;
if (hour >= 17 && hour <= 23)
cout << "You're off work! Relax!" << endl;
}
return 0;
}


  Re: Help with Easy Prog  e40pud at 09:17 on Friday, April 25, 2008
 


#include <iostream>
using namespace std;

int main() {
int hour = 0;
char day = 'q';

while (day != 'S' && day != 'M' && day != 'T' && day != 'W' && day != 'R' && day != 'F' && day != 'A')
{
cout << "What day is it?" << endl << "Please enter your response with a capital letter: S, M, T, W, R, F, or A" << endl;
cin >> day;
if (day != 'S' && day != 'M' && day != 'T' && day != 'W' && day != 'R' && day != 'F' && day != 'A')
cout << "Invalid entry" << endl;
}
if (day == 'S' || day == 'A')
cout << "Enjoy the weekend! Yay!" << endl;
else {
while (hour <= 0 || hour >= 23)
{
cout << "What hour is it?" << endl << "Enter a number between 0 and 23" << endl;
cin >> hour;
if (hour <= 0 || hour >= 23)
cout << "Invalid hour" << endl;
}
if (hour >= 8 && hour <= 17)
cout << "You should be working! Get back to work!" << endl;
if (hour >= 0 && hour <= 8)
cout << "Go back to sleep!" << endl;
if (hour >= 17 && hour <= 23)
cout << "You're off work! Relax!" << endl;
}
return 0;
}


<Added>


this code is work ...








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Perl Script - File Handling.
•  Empty the contents of a file.
•  Month Start, End dates
•  show hide problem in dynamic table creation
•  Re: ASP Sendmail has huge delay - ANYONE??
•  Re: Perl Scripting Strings
•  Re: how to create forum using asp.net with c# language?
•  Re: datasource
•  jhjgjgjghjjghjghj


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008