943,850 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 912
  • C++ RSS
Apr 24th, 2009
0

if else statement ???? c++

Expand Post »
I`m trying to to use if statement but something going wrong.
statement must be 2 steps
IF There is still room in the array and
IF there is not an Appointmen on the same Date and Time!
Apointment will be accept......
im not getting any error or worning
but its not chaking second if statement and both else printing together
C++ Syntax (Toggle Plain Text)
  1. void addAppointmenRecords( )
  2. {
  3. int number, i,k;
  4. system("cls"); //clear screen
  5. cout<<"\nHow many Appointmen you wish to add? ";
  6. cin>>number; //read number
  7. cin.get(); //read newline character left in the buffer
  8.  
  9. if((number + currentSize ) <= listSize) //There is still room in the array
  10. {
  11. for( i = 1; i<=number; i++ )
  12. {
  13. cout<<"\nEnter Person name: ";
  14. getline(cin, AppointmenList[currentSize].name);
  15. cout<<"Enter Appointmen Descriptions: ";
  16. getline(cin, AppointmenList[currentSize].description);
  17. cout<<"Enter Appointmen date: ";
  18. cin>>AppointmenList[currentSize].appdate.day;
  19. cin>>AppointmenList[currentSize].appdate.mounth;
  20. cin>>AppointmenList[currentSize].appdate.year;
  21. cin.get(); //read a character
  22. cout<<"Enter Appointmen time: ";
  23. getline(cin, AppointmenList[currentSize].time);
  24. cout<<endl;
  25. currentSize += 1; //update CurrentSize
  26.  
  27.  
  28. for(k=0; k<currentSize; k++) //chech if there an Appointmen on the same Date and Time!
  29. if( AppointmenList[currentSize].appdate.day == AppointmenLis[k].appdate.day &&
  30. AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
  31. AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
  32. AppointmenList[currentSize].time == AppointmenList[k].time )
  33. {
  34. cout<<"\nGot a match\n";
  35. cout<<"Appointmen Date and Time already filled"<<endl;
  36. currentSize-=1;
  37. }
  38. else
  39. {
  40. cout<<"Apointment accepted"<<endl;
  41. currentSize+=1;
  42. }
  43. }
  44. }
  45. else
  46. {
  47. cout<<"Overflow!!!! Appointmen List is full"<<endl;
  48. cout<<"\nPress any key to continue"<<endl;
  49. cin.get(); //read a character
  50. }
  51. }
Similar Threads
Reputation Points: 12
Solved Threads: 0
Light Poster
pczafer is offline Offline
38 posts
since Apr 2009
Apr 24th, 2009
0

Re: if else statement ???? c++

I don't get your question, can you please explain it in a way I can understand ?

By the way, If you've some additional time please format your code properly (using code tags was the first (and very good) step, formatting your code is the second one) ...

Edit:: Avoid using the system(); command (look here)...
Last edited by tux4life; Apr 24th, 2009 at 5:06 pm.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Apr 24th, 2009
0

Re: if else statement ???? c++

i used the tags for my codes
anyway
i was meaning i can still insert Appointmen on the same Date and Time. and printing
C++ Syntax (Toggle Plain Text)
  1. "Apointment accepted"
and
C++ Syntax (Toggle Plain Text)
  1. "Appointmen Date and Time already filled"
after every entry
Reputation Points: 12
Solved Threads: 0
Light Poster
pczafer is offline Offline
38 posts
since Apr 2009
Apr 24th, 2009
0

Re: if else statement ???? c++

Please, make this terrible code refactoring as soon as possible:
1. Stop using of global variables immediately. Pass appointment list array, its capacity (max size) and a reference to the current free index as addAppointmentRecords arguments.
2. Use operator == for appdate structures instead of these awful member by member comparisons.
3. Use break statement after "already filled" message.
4. Make a proper indentation: it's impossible to read (and understand) this nightmare now...

Next time add main data structures definitions to the snippet. Use code tag with the language specifier (feel the difference):
[code=cplusplus]
source
[/code]
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Apr 24th, 2009
0

Re: if else statement ???? c++

Wow that is just too painful to read. Curly brackets all over the place. Fix it up a bit please.
Reputation Points: 352
Solved Threads: 109
Master Poster
skatamatic is offline Offline
776 posts
since Nov 2007
Apr 24th, 2009
0

Re: if else statement ???? c++

I think the curly brackets don't add up correctly you maybe missing some.

I would suggest indenting your code properley to make it more readable.

eg

C++ Syntax (Toggle Plain Text)
  1. while(something)<blockquote>{</blockquote><blockquote><blockquote>if(somethingelse)</blockquote></blockquote><blockquote><blockquote><blockquote>{</blockquote></blockquote></blockquote><blockquote><blockquote><blockquote><blockquote>do something</blockquote></blockquote></blockquote></blockquote><blockquote><blockquote><blockquote>}</blockquote></blockquote></blockquote><blockquote>}</blockquote>

Without the extra lines in between.
Last edited by Xlphos; Apr 24th, 2009 at 8:31 pm.
Reputation Points: 32
Solved Threads: 116
Veteran Poster
Xlphos is offline Offline
1,073 posts
since Apr 2008
Apr 25th, 2009
1

Re: if else statement ???? c++

sorry for my codes everyone im still biginer..
i used code=cplusplus
source
/code
but still looking a bit mess i hope its more readable now.
C++ Syntax (Toggle Plain Text)
  1. void addAppointmenRecords( )
  2. {
  3. system("cls"); //clear screen
  4. cout<<"\nHow many Appointmen you wish to add? ";
  5. cin>>number; //read number
  6. cin.get(); //read newline character left in the buffer
  7. if((number + currentSize ) <= listSize) //There is still room in the array
  8. {
  9. for(int i = 1; i<=number; i++ )
  10. {
  11. cout<<"\nEnter Person name: ";
  12. getline(cin, AppointmenList[currentSize].name);
  13. cout<<"Enter Appointmen Descriptions: ";
  14. getline(cin, AppointmenList[currentSize].description);
  15. cout<<"Enter Appointmen date: ";
  16. cin>>AppointmenList[currentSize].appdate.day;
  17. cin>>AppointmenList[currentSize].appdate.mounth;
  18. cin>>AppointmenList[currentSize].appdate.year;
  19. cin.get(); //read a character
  20. cout<<"Enter Appointmen time: ";
  21. getline(cin, AppointmenList[currentSize].time);
  22. cout<<endl;
  23. currentSize += 1; //update CurrentSize
  24. for(int k=0; k<currentSize; k++) //chech if there an Appointmen on the same Date and Time!
  25. if( AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day &&
  26. AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
  27. AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
  28. AppointmenList[currentSize].time == AppointmenList[k].time )
  29. {
  30. cout<<"\nGot a match\n";
  31. cout<<"Appointmen Date and Time already filled"<<endl;
  32. currentSize-=1;
  33. break;
  34. }
  35. else
  36. {
  37. cout<<"Apointment accepted"<<endl;
  38. currentSize+=1;
  39. }
  40. }
  41. }
  42. else
  43. {
  44. cout<<"Overflow!!!! Appointmen List is full"<<endl;
  45. cout<<"\nPress any key to continue"<<endl;
  46. cin.get(); //read a character
  47. }
  48. }
Reputation Points: 12
Solved Threads: 0
Light Poster
pczafer is offline Offline
38 posts
since Apr 2009
Apr 25th, 2009
0

Re: if else statement ???? c++

Have you tried putting curly brackets after the for loop on line 24?

for()

open with {

if()

open with{

do something

end if with }

end for with}
Reputation Points: 32
Solved Threads: 116
Veteran Poster
Xlphos is offline Offline
1,073 posts
since Apr 2008
Apr 26th, 2009
0

Re: if else statement ???? c++

sorry for my codes i tryed to clean a bit more
its not checking
Quote ...
if there an Appointmen on the same Date and Time!
and printing
Quote ...
"Apointment accepted"
and
Quote ...
Got a match
Appointment Date and Time already filled
can anybody see mistakes now??????

C++ Syntax (Toggle Plain Text)
  1. void addAppointmenRecords( )
  2. {
  3. int number, i,k;
  4. system("cls"); //clear screen
  5. cout<<"\nHow many Appointments do you wish to add? ";
  6. cin>>number; //read number
  7. cin.get(); //read newline character left in the buffer
  8.  
  9. if((number + currentSize ) <= listSize)//There is still room in the array
  10. {
  11. for( i = 1; i<=number; i++ )
  12. {
  13. cout<<"\nEnter Person name: ";
  14. getline(cin, AppointmenList[currentSize].name);
  15. cout<<"Enter Appointment Descriptions: ";
  16. getline(cin, AppointmenList[currentSize].description);
  17. cout<<"Enter Appointment date: ";
  18. cin>>AppointmenList[currentSize].appdate.day;
  19. cin>>AppointmenList[currentSize].appdate.mounth;
  20. cin>>AppointmenList[currentSize].appdate.year;
  21. cin.get();//read a character
  22. cout<<"Enter Appointment time: ";
  23. getline(cin, AppointmenList[currentSize].time);
  24. cout<<endl;
  25. currentSize += 1; //update CurrentSize
  26. for(k=0; k<currentSize; k++)//check if there an Appointmen on the same Date and Time!
  27. {
  28. if(AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day &&
  29. AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth &&
  30. AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year &&
  31. AppointmenList[currentSize].time == AppointmenList[k].time )
  32. {
  33. cout<<"\nGot a match\n";
  34. cout<<"Appointment Date and Time already filled"<<endl;
  35. currentSize-=1;
  36. break;
  37. }
  38. else
  39. {
  40. cout<<"Apointment accepted"<<endl;
  41. currentSize+=1;
  42. }
  43. }
  44. }
  45. }
  46. else
  47. {
  48. cout<<"Overflow!!!! Appointment List is full"<<endl;
  49. cout<<"\nPress any key to continue"<<endl;
  50. cin.get(); //read a character
  51. }
  52. }
Reputation Points: 12
Solved Threads: 0
Light Poster
pczafer is offline Offline
38 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: creating exe from program
Next Thread in C++ Forum Timeline: Adding Or Changing the Text Of Child Nodes in TreeView - Visual c++ 2008





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC