צריך עזרה ב cpp {כולל קוד מקור}

nimrodshay

New member
צריך עזרה ב cpp {כולל קוד מקור}

יש בתוכנית חלק ששואל ככה what fo you want to do 1.continue 2.exit ושבוחרים ב exit אז זה לא יוצא אלה ממשיך למה??? נ.ב אני יודע שיש הרבה הערות וזה לא בנוי יפה כי יש לי סיבות אבל לא משנה כרגע, בבקשה תנסו לעזור הנה הקוד מקור
/* program that calculate avrege of marks version 1.0 built by nimrod shay, all rights reserved contact me at [email protected] */ #include <iostream.h> #include <conio.h> #include <conio.c> /* function that calculate avrege*/ double avrege(double total_marks, double number_of_marks_f) { return total_marks / number_of_marks_f; } main() { /* getting number of marks to calculate their avrege*/ double counter,total,number_of_marks,mark; int nimrod,choice; char ch; /*starting loop for all of the program */ while (ch != ´n´) { clrscr(); cout<<" ----written by nimrod shay-----"<<"\n"<<"\n"; cout<<"Enter the number of marks you want to calculate their avrege:"<<"\n"; cin>>number_of_marks; /* start to get the marks from the user with loop */ total=0; for(counter = 0; counter < number_of_marks; counter++) { cout<<"enter next mark:"<<"\n"; cin>>mark; total = total + mark; } /* display the avrege */ cout<<"avrege :"<< avrege(total,number_of_marks)<<"\n"<<"\n"; /* display a nice and friendly menu */ cout<<"what do you want to do now?"<<"\n"<<"1.continue"<<"\n"<<"2.exit"<<"\n"; cin>>choice; if (choice = ´2´) { nimrod=´n´; } else { nimrod=´y´; } } return 0; }​
 

Elk

New member
התבלבלת קצת

אתה שואל על ch, ובעצם אתה מעדכן את nimrod.
 

ke

New member
== ולא =

בבדיקה של choice השתמשת ב = במקום ב == כלומר במקום,
if (choice = ´2´)​
צריך להיות
if (choice == ´2´)​
 

ihovav

New member
כמו ש KE כתב

הסימן " = " זה השמז - ואתה למעשה מכניס ערך מסויים לתוך המשתנה - ולכן התכנית לא יוצאת אתה צריך לכתוב " == " שזה השוואה - ואז התכנית תצא
 

nimrodshay

New member
הנה עשיתי את השינויים האלו אבל זה..

עדיין לא יוצא אם בוחרים ב 2
/* program that calculate avrege of marks version 1.0 built by nimrod shay, all rights reserved contact me at [email protected] */ #include <iostream.h> #include <conio.h> #include <conio.c> /* function that calculate avrege*/ double avrege(double total_marks, double number_of_marks_f) { return total_marks / number_of_marks_f; } main() { /* getting number of marks to calculate their avrege*/ double counter,total,number_of_marks,mark; int nimrod,choice; char ch; /*starting loop for all of the program */ while (ch != ´n´) { clrscr(); cout<<" ----written by nimrod shay-----"<<"\n"<<"\n"; cout<<"Enter the number of marks you want to calculate their avrege:"<<"\n"; cin>>number_of_marks; /* start to get the marks from the user with loop */ total=0; for(counter = 0; counter < number_of_marks; counter++) { cout<<"enter next mark:"<<"\n"; cin>>mark; total = total + mark; } /* display the avrege */ cout<<"avrege :"<< avrege(total,number_of_marks)<<"\n"<<"\n"; /* display a nice and friendly menu */ cout<<"what do you want to do now?"<<"\n"<<"1.continue"<<"\n"<<"2.exit"<<"\n"; cin>>choice; if (choice == ´2´) { ch=´n´; } else { ch=´y´; } } return 0; }​
 

emissary

New member
אהה

למה התנאי שלך יש גרשיים לא צריך להיות. שמים גרשיים כשרוצים להפוך מתו לקוד אסקי התנאי צריך להיות ככה
if( choice == 2)​
 
למעלה