Hi there
I have tried to fix your program but because I don't know when you should have positive and when negative answer I can't fix it all.
there was lots things that could be corrected.
1. you didn't have #include <iostream> possibly becuse you did't need in your version of the code? (I didn't use printf and scanf.)
2. When you paste your code use tags to start "[" code "]" and to finish "[" /code "]" without quotes of course.
3. Don't compact your code (you are NOT ZIP ;P) white spaces are ignored in C++ so you can make extra space, it will make your code more readable.
4. if you select UM (unmarried) in your code there is nothing about this so it jumps directly to last else statement.
5. Statement like this if(sex==m&&age>=30), well not sure what more experienced developers will say about this but I don't like it. in this form. Its ok I guess, does not breaks rules, but I would prefer to add nested else if statement and ask for age inside. This gives you more options, not only 30 years, other ranges.
6. Char should be in single quotes
not like this if(ms==M) but like this if(ms == 'M')
As for your IDE you can use
http://www.codeblocks.org
or Microsoft Visual Studio
I hope that will help you :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include<stdio.h>
#include <iostream>
using namespace std;
int main()
{
char ms,sex;
int age;
cout << "enter your marital status M/UM: ";
cin >> ms;
cout << "enter your age: ";
cin >> age;
cout << "enter your sex: ";
cin >> sex;
if (ms =='M' || ms == 'm')
{
cout << "driver will be insured";
}
else if (sex =='m' && sex == 'M')
{
if (age >= 30)
{
cout << "driver will be insured";
}
else
{
cout << "Sorry mate!";
}
}
else if (sex == 'f' && age >= 25)
{
cout << "driver will be insured";
}
else
{
cout << "driver won't be insured";
}
return 0;
}
|