| | |
if else statement ???? c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
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
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)
void addAppointmenRecords( ) { int number, i,k; system("cls"); //clear screen cout<<"\nHow many Appointmen you wish to add? "; cin>>number; //read number cin.get(); //read newline character left in the buffer if((number + currentSize ) <= listSize) //There is still room in the array { for( i = 1; i<=number; i++ ) { cout<<"\nEnter Person name: "; getline(cin, AppointmenList[currentSize].name); cout<<"Enter Appointmen Descriptions: "; getline(cin, AppointmenList[currentSize].description); cout<<"Enter Appointmen date: "; cin>>AppointmenList[currentSize].appdate.day; cin>>AppointmenList[currentSize].appdate.mounth; cin>>AppointmenList[currentSize].appdate.year; cin.get(); //read a character cout<<"Enter Appointmen time: "; getline(cin, AppointmenList[currentSize].time); cout<<endl; currentSize += 1; //update CurrentSize for(k=0; k<currentSize; k++) //chech if there an Appointmen on the same Date and Time! if( AppointmenList[currentSize].appdate.day == AppointmenLis[k].appdate.day && AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth && AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year && AppointmenList[currentSize].time == AppointmenList[k].time ) { cout<<"\nGot a match\n"; cout<<"Appointmen Date and Time already filled"<<endl; currentSize-=1; } else { cout<<"Apointment accepted"<<endl; currentSize+=1; } } } else { cout<<"Overflow!!!! Appointmen List is full"<<endl; cout<<"\nPress any key to continue"<<endl; cin.get(); //read a character } }
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
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."
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
i used the tags for my codes
anyway
i was meaning i can still insert Appointmen on the same Date and Time. and printing and
after every entry
anyway
i was meaning i can still insert Appointmen on the same Date and Time. and printing
C++ Syntax (Toggle Plain Text)
"Apointment accepted"
C++ Syntax (Toggle Plain Text)
"Appointmen Date and Time already filled"
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]
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]
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
Without the extra lines in between.
I would suggest indenting your code properley to make it more readable.
eg
C++ Syntax (Toggle Plain Text)
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!
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
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.
i used code=cplusplus
source
/code
but still looking a bit mess i hope its more readable now.
C++ Syntax (Toggle Plain Text)
void addAppointmenRecords( ) { system("cls"); //clear screen cout<<"\nHow many Appointmen you wish to add? "; cin>>number; //read number cin.get(); //read newline character left in the buffer if((number + currentSize ) <= listSize) //There is still room in the array { for(int i = 1; i<=number; i++ ) { cout<<"\nEnter Person name: "; getline(cin, AppointmenList[currentSize].name); cout<<"Enter Appointmen Descriptions: "; getline(cin, AppointmenList[currentSize].description); cout<<"Enter Appointmen date: "; cin>>AppointmenList[currentSize].appdate.day; cin>>AppointmenList[currentSize].appdate.mounth; cin>>AppointmenList[currentSize].appdate.year; cin.get(); //read a character cout<<"Enter Appointmen time: "; getline(cin, AppointmenList[currentSize].time); cout<<endl; currentSize += 1; //update CurrentSize for(int k=0; k<currentSize; k++) //chech if there an Appointmen on the same Date and Time! if( AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day && AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth && AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year && AppointmenList[currentSize].time == AppointmenList[k].time ) { cout<<"\nGot a match\n"; cout<<"Appointmen Date and Time already filled"<<endl; currentSize-=1; break; } else { cout<<"Apointment accepted"<<endl; currentSize+=1; } } } else { cout<<"Overflow!!!! Appointmen List is full"<<endl; cout<<"\nPress any key to continue"<<endl; cin.get(); //read a character } }
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}
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!
•
•
Join Date: Apr 2009
Posts: 24
Reputation:
Solved Threads: 0
sorry for my codes i tryed to clean a bit more
its not checking and printing and can anybody see mistakes now??????
its not checking
•
•
•
•
if there an Appointmen on the same Date and Time!
•
•
•
•
"Apointment accepted"
•
•
•
•
Got a match
Appointment Date and Time already filled
C++ Syntax (Toggle Plain Text)
void addAppointmenRecords( ) { int number, i,k; system("cls"); //clear screen cout<<"\nHow many Appointments do you wish to add? "; cin>>number; //read number cin.get(); //read newline character left in the buffer if((number + currentSize ) <= listSize)//There is still room in the array { for( i = 1; i<=number; i++ ) { cout<<"\nEnter Person name: "; getline(cin, AppointmenList[currentSize].name); cout<<"Enter Appointment Descriptions: "; getline(cin, AppointmenList[currentSize].description); cout<<"Enter Appointment date: "; cin>>AppointmenList[currentSize].appdate.day; cin>>AppointmenList[currentSize].appdate.mounth; cin>>AppointmenList[currentSize].appdate.year; cin.get();//read a character cout<<"Enter Appointment time: "; getline(cin, AppointmenList[currentSize].time); cout<<endl; currentSize += 1; //update CurrentSize for(k=0; k<currentSize; k++)//check if there an Appointmen on the same Date and Time! { if(AppointmenList[currentSize].appdate.day == AppointmenList[k].appdate.day && AppointmenList[currentSize].appdate.mounth == AppointmenList[k].appdate.mounth && AppointmenList[currentSize].appdate.year == AppointmenList[k].appdate.year && AppointmenList[currentSize].time == AppointmenList[k].time ) { cout<<"\nGot a match\n"; cout<<"Appointment Date and Time already filled"<<endl; currentSize-=1; break; } else { cout<<"Apointment accepted"<<endl; currentSize+=1; } } } } else { cout<<"Overflow!!!! Appointment List is full"<<endl; cout<<"\nPress any key to continue"<<endl; cin.get(); //read a character } }
![]() |
Similar Threads
- missing return statement (Java)
- MySQL LIKE statement (MySQL)
- loop in main function to an "if" statement (C++)
- Switch Case Statement (Java)
- run sql statement in asp (ASP)
- switch/case statement (C++)
- change statement (JSP)
- Reading MSWord Document through an ASP Statement (ASP)
Other Threads in the C++ Forum
- Previous Thread: Practice problems in C/C++
- Next Thread: Adding Or Changing the Text Of Child Nodes in TreeView - Visual c++ 2008
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






