C++ practice/exercise

Sep 11, 2009 at 1:26pm
I am reading the tutorials to learn C++, but I need to practice otherwise I'm not going to remember what I'm learning. Does anyone know a way for me to do some exercises or a project in which I could be involved ?? I have got a compiler (code block).

Thanks.
Sep 11, 2009 at 1:33pm
Try some of these exercises: http://www.cplusplus.com/forum/articles/12974/
And mess a bit with the code example you find in the tutorials, that helps a lot
Last edited on Sep 11, 2009 at 1:34pm
Sep 11, 2009 at 2:31pm
Thank you very much, that should help me a lot.
Sep 11, 2009 at 3:24pm
In the first exercise, it mentions switch statements, I don't know how it is possible to use switch statement to resolve this particular exercise. I used only "if statement" :

if ((score<=100)&&(score>=90))
cout<<"Level A"<<endl;
else if ((score<=89)&&(score>=80))
cout<<"Level B"<<endl;
else if ((score<=79)&&(score>=70))
cout<<"Level C"<<endl;
else if ((score<=69)&&(score>=60))
cout<<"Level D"<<endl;
else if ((score<=59)&&(score>=0))
cout<<"Level F"<<endl;


??
Sep 11, 2009 at 3:29pm
Something like:
1
2
3
4
5
6
switch ( score )
{
     case 100: case 99: case 90: case 89: //...
          cout << "Level A";
     // etc.
}
The 'if' is better for this...
Sep 11, 2009 at 3:46pm
That's what I thought. Thank for your help.
Sep 11, 2009 at 6:23pm
'switch' only supported by integer.
Sep 11, 2009 at 10:16pm
So? what do you think 'score' is, a potato bag?
Anyway, with C++0x switch should work with any type
Sep 11, 2009 at 10:29pm
Anyway, with C++0x switch should work with any type


Ooh cool!
Topic archived. No new replies allowed.