if else statement ???? c++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 24
Reputation: pczafer is an unknown quantity at this point 
Solved Threads: 0
pczafer pczafer is offline Offline
Newbie Poster

if else statement ???? c++

 
0
  #1
Apr 24th, 2009
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
  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. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

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

 
0
  #2
Apr 24th, 2009
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.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: pczafer is an unknown quantity at this point 
Solved Threads: 0
pczafer pczafer is offline Offline
Newbie Poster

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

 
0
  #3
Apr 24th, 2009
i used the tags for my codes
anyway
i was meaning i can still insert Appointmen on the same Date and Time. and printing
  1. "Apointment accepted"
and
  1. "Appointmen Date and Time already filled"
after every entry
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

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

 
0
  #4
Apr 24th, 2009
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]
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

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

 
0
  #5
Apr 24th, 2009
Wow that is just too painful to read. Curly brackets all over the place. Fix it up a bit please.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 621
Reputation: Xlphos is an unknown quantity at this point 
Solved Threads: 74
Xlphos's Avatar
Xlphos Xlphos is offline Offline
Practically a Master Poster

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

 
0
  #6
Apr 24th, 2009
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

  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.
I don't mind helping but please mark your thread as solved once the problem is sorted. If you figure it out tell us how you did it, don't just abandon your thread!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: pczafer is an unknown quantity at this point 
Solved Threads: 0
pczafer pczafer is offline Offline
Newbie Poster

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

 
1
  #7
Apr 25th, 2009
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.
  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. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 621
Reputation: Xlphos is an unknown quantity at this point 
Solved Threads: 74
Xlphos's Avatar
Xlphos Xlphos is offline Offline
Practically a Master Poster

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

 
0
  #8
Apr 25th, 2009
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}
I don't mind helping but please mark your thread as solved once the problem is sorted. If you figure it out tell us how you did it, don't just abandon your thread!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 24
Reputation: pczafer is an unknown quantity at this point 
Solved Threads: 0
pczafer pczafer is offline Offline
Newbie Poster

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

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

  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. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC