|
-
September 7th, 2010, 11:32 AM
#1
Need Help with writing this Program!
Hey guys!
I'm new to coding and having a difficulty. I am suppose to create a program in Visual Studio. Here's the instructions:
Write a program that asks the user to enter either character ‘a’ or ‘b’ from the keyboard. If the user enters ‘a’ then prompt the user to input three floating- point numbers and print the sum and average, of three numbers. If the user enters ‘b’, then prompt the user to enter three initials of first name, middle name, and last name Print the initials. The screen dialogue should appear as follows. . Hint: You need to use if statement i.e.
if x > y
statement1;
else
statement2;
Enter character ‘a’ or ‘b’: a
Enter three floating-point numbers: -3 5 8
Sum = 10
Average = 3.33
Or
Enter character ‘a’ or ‘b’: b
Enter first initial: N
Enter first initial: B
Enter first initial: C
Your initial is: NBC
Here's what I have so far. I believe my if and else area is not right! Please help me out!
#include <iostream>
using namespace std;
int main ()
{
float number1, number2, number3;
char ch1='a', ch2='b';
int sum, average;
cout <<"Please enter a or b"
cin >> ch1 >> ch2;
if (ch1=='a')
cout <<"Please input the three floating point numbers and print the sum and average of three numbers"
else cout<<"Please enter three initials of your first name, middle name, and last name"
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|