Welcome! Log In Create A New Profile

Advanced

Assignment 2

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
Assignment 2
March 12, 2009 10:24AM
Hi All!

I am confused with question 1a of assignment 2. Can someone help!! my answer is:
#include <iostream>
using namespace std;

int main()
{
char c1,c2,c3;
int i;
i=0;

do
{
i++;
cout<<"Enter a first character"<<endl;
cin>>c1;

cout<<"Enter a second character"<<endl;
cin>>c2;

cout<<"Enter a third character"<<endl;
cin>>c3;

cout<<c1<<c2<<c3<<endl;
}while (c1 != c2 && c3 != 'x'winking smiley;

return 0;
}
avatar Re: Assignment 2
March 12, 2009 11:37AM
Question 1a
Suppose we want to input and validate three characters in a do..while loop. The variable names are c1, c2 and
c3. The values of c1 and c2 may not be the same and c3 may not be equal to X. If this condition does not hold, the
loop has to be executed again
. Write down a correct condition for the do..while loop.

Take note of the following in the above sentence and interpret accordingly (ie. how do you interpret this ??)

If this condition does not hold, the
loop has to be executed again
thumbs up smiley
Re: Assignment 2
March 16, 2009 08:37AM
Hi Wiseguy!

The question wants me to write a program that will accept three characters and these (c1,c2,c3) characters must be accepted while thier condition are c1 not the same with c2 and c3 not equal X....


#include <iostream>
using namespace std;

int main()
{
char c1,c2,c3;

do
{
cout<<"Enter a character;";
cin>>c1;
cout<<"Enter second character;";
cin>>c2;
cout<<"Enter a third character";
cin>>c3;

}while((c3 != 'X'winking smiley && (c1 != c2)&&(c2 != c1));

return 0;
}
Re: Assignment 2
March 25, 2009 01:38PM
Hi,

Just remember that the question asks for just the specific condition & not the entire program.

Also, consider placing each condition within a bracket with the && expression joining the 2 conditions.

Good luck!

Kronic
Sorry, only registered users may post in this forum.

Click here to login