CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Sep 2018
    Posts
    2

    Talking anyone can help me with this?

    Write a program that asks the user to enter three real numbers. if all three numbers are positives, print the sum else if one number is negative print the product of the two positive numbers. you will then ask the user to enter two real numbers. if both numbers are negative print the quotient, otherwise terminate the program. use fixed mode and format the output, in other words, specify the width and the number of digits meaningful variable names and informative prompts

    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

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    	int x, y;
    	cout << "Enter 2 intergers";
    	cin >> x >> y;
    	
    	//simple ifs
    	if (x > 0) cout << "The firs number is positive";
    	if (x > 0 && y > 0) cout << "Both are positive";
    	if (x > 0 || y > 0) cout << "At least one number is positive";
    
    
    	//if-else 
    	if (x > 0)cout << "The firs number is positive";
    	else cout << "The first number is not positive";
    	if (x > 0 || y > 0) cout << "at least one number is positive";
    	else cout << "Both number are negative";
    
    	//nested ifs
    	if (x > 0) if (y > 0) cout << "Both are positive";
    	else cout << "First number is positive, Second not positive";
    	else cout << "First not positive, Second don't know";
    
    
    	float a, b;
    	cout << "Enter 2 real numbers";
    	cin >> a >> b;
    	cout << fixed << setprecision(2);
    	if (a > 0 && b > 0) cout << "sum" << setw(12) << a + b << endl;
    	return 0;
    }
    Edit & Run
    Last edited by 2kaud; September 12th, 2018 at 02:03 PM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured