Welcome! Log In Create A New Profile

Advanced

Question 1.Assign1 semester2

Posted by tshax 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Question 1.Assign1 semester2
July 20, 2009 04:38PM
Hi All!

I am not quite sure which iteration loop to use between while loop or do while loop. But i found if statement perfect for this question, check the code below:
spinning smiley sticking its tongue out

if (ans=='y' || ans=='Y'winking smiley
{
cout<<"How many modules repeating?"<<endl;
cin>>no_repeat;
total = calcFee(no_module, fees, no_repeat, repeat_fees);
}
else
{
total= calcFee(no_module, fees);
}
Anyone with different opinion please advise...smileys with beer
avatar Re: Question 1.Assign1 semester2
July 20, 2009 08:29PM
If you want your loop to happen 0 or more times -> while loop

If you want your loop to happen 1 or more times -> do ... while loop
Re: Question 1.Assign1 semester2
August 04, 2009 03:52PM
Hi there,

My suggestion to you is for you not to use the ELSE statement, the program must call the "New module" function no matter if the student is repeating moules or not.

Good luck!
Re: Question 1.Assign1 semester2
August 05, 2009 04:12AM
Hi Everyone.

I have a bit of a problem with validating my input and would really appreciate your help. I will post the code and then explain the problem.

Language: C++
if ((repeat == ';Y';)or(repeat == ';y';)) {   cout<<"\nHow many modules will the student repeat? : "; cin>>repEnrolled;   cout<<"\nHow many new modules will the student take? : "; cin>>newEnrolled;   totalTuition=calcFees(newEnrolled, NEW_FEE, repEnrolled, REPEAT_FEE);   }//if loop else {   cout<<"\nHow many new modules will the student take? : "; cin>>newEnrolled;   totalTuition=calcFees(newEnrolled, NEW_FEE);   }//else loop

Ok, now basically, everything works fine when I use valid input, but when I use invalid input e.g. a character or floating point value instead of an integer, the program goes a bit crazy. How can I validate the input as integer values?
Having looked on the web, there were solutions like using cin.good() in a while loop which resulted in an infinite loop.
Let me know what you guys think.

Thanks

Chris Botha

=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt
Sorry, only registered users may post in this forum.

Click here to login