Results 1 to 8 of 8

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User rumen_33's Avatar
    Join Date: May:2007
    Location: Canada
    Posts: 137

    C++

    . : - , . , 3 . 2 , : . : 2 1 - . , : . : 0 , : ! . , . DO-WHILE loop IF statement, , , . . :

    #include <cstdlib>
    #include <iostream>

    using namespace std;


    int main() {
    // Variables
    int randnum, usernum, chancenum = 2;


    // Random Number Generator
    srand(time(0));
    randnum = rand()% 10 + 1;


    // Welcoming Text
    cout << "The random number is:" << randnum << endl;
    cout <<"Welcome to the Number Guessing Game!!\n";
    cout <<"************************************* \n\n";
    cout <<"Try to guess the number that has been generated.\n";
    cout <<"Please enter a number between 1 and 10 (including 1 and 10): ";


    // Begining of a DO - WHILE Loop
    do {
    cin >> usernum;
    if (randnum == usernum)
    cout << "That is correct, you win!\n\nThank you for playing the Number Guessing Game!\n\n\n";
    else {
    cout << "Sorry, this is incorrect. You have " << chancenum << " more chances left";
    chancenum--;
    }
    } while (chancenum >= 0 && randnum != usernum);


    // Execution Definitions
    system("PAUSE");
    return EXIT_SUCCESS;
    }
    |Asus P5K Premium WiFi|Intel C2D E6750|Kingston 2x1GB@667MHz|Seagate 250GB+500GB|Coolmax CP 500W|Asus EN 8800 GTS 320MB|

  2. #2
    WarLord's Avatar
    Join Date: May:2003
    Location:
    Posts: 129
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    
    int main() {
    // Variables
    int randnum, usernum, chancenum = 2;
    
    
    // Random Number Generator
    srand(time(0));
    randnum = rand()% 10 + 1;
    
    
    // Welcoming Text
    cout << "The random number is:" << randnum << endl;
    cout <<"Welcome to the Number Guessing Game!!\n";
    cout <<"************************************* \n\n";
    cout <<"Try to guess the number that has been generated.\n";
    cout <<"Please enter a number between 1 and 10 (including 1 and 10): ";
    
    
    // Begining of a DO - WHILE Loop
    do {
    	cin >> usernum;
    	if (randnum == usernum)
    		cout << "That is correct, you win!\n\nThank you for playing the Number Guessing Game!\n\n\n";
    	else 
    		if(chancenum == 0)
    			cout<<"You Lose! :("<<"\n";
    		else
    		{
    			cout << "Sorry, this is incorrect. You have " << chancenum << " more chances left";
    			--chancenum;
    		}
    	} while (chancenum >= 0 && randnum != usernum);
    
    
    // Execution Definitions
    system("PAUSE");
    return EXIT_SUCCESS;
    }
    Thou hast not to like it, thou hast just to do it.

  3. #3
    Registered User rumen_33's Avatar
    Join Date: May:2007
    Location: Canada
    Posts: 137
    . . , if, else, . ! !
    |Asus P5K Premium WiFi|Intel C2D E6750|Kingston 2x1GB@667MHz|Seagate 250GB+500GB|Coolmax CP 500W|Asus EN 8800 GTS 320MB|

  4. #4
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    :
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <time.h>
    
    using namespace std;
    
    
    int main() {
    // Variables
    int randnum, usernum, chancenum = 3;
    
    
    // Random Number Generator
    srand(time(0));
    randnum = rand()% 10 + 1;
    
    
    // Welcoming Text
    cout << "The random number is:" << randnum << endl;
    cout <<"Welcome to the Number Guessing Game!!\n";
    cout <<"************************************* \n\n";
    cout <<"Try to guess the number that has been generated.\n";
    
    // Begining of a DO - WHILE Loop
    do {
       cout <<"Please enter a number between 1 and 10 (including 1 and 10): ";
       cin >> usernum;
       if (randnum == usernum)
          cout << "That is correct, you win!\n\nThank you for playing the Number Guessing Game!\n\n\n";
       else {
              if (--chancenum)
                 cout << "Sorry, this is incorrect. You have " << chancenum << " more chances left\n";
            }
       } 
    while (chancenum > 0 && randnum != usernum);
    //End of DO-WHILE
    
    if (!chancenum) cout << "Incorrect, you lose\n\n";
    
    
    // Execution Definitions
    system("PAUSE");
    return EXIT_SUCCESS;
    }
    , , -. , Warning srand, unsigned int. , , , .
    Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19

  5. #5
    Ronnie James Dio Snow's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 8,221
    . (, , ), , : "^" , float? Visual Studio 2008 .

    Code:
    #include "stdafx.h"
    #include "stdio.h"
    #include "math.h"
    
    int main()
    {
    float a, b, c, p, s,r ;
    printf("A e:");
    scanf("%f", &a);
    printf("B e:");
    scanf("%f", &b);
    printf("C e:");
    scanf("%f", &c);
    p=(a+b+c)/2;
    r=a/2;
    s = sqrt(p*((p-c)*(p-c)*(p-a)))+ (a*b) + (3.14*(r^2));
    
    printf("Powyrhninata e:", s);
    
    
    return 0;
    }
    : error C2296: '^' : illegal, left operand has type 'float'
    ?
    MSI B550i Gaming Edge Wifi | Ryzen 9 5900X [Thermalright AXP-100C65 + Noctua A9x14] | G.Skill 2x16GB F4-3200C16Q-32GTZR | AMD RX 6800XT | EVO970 500GB + EVO850 250GB + EVO850 500GB + DS119j | Corsair SF750 Platinum | ASUS MG279Q | Razer DeathAdder V2 Pro | Keychron K6 Modded | SligerSM550

  6. #6
    Pesho's Avatar
    Join Date: Nov:2001
    Location: Sofia
    Posts: 5,169
    Quote Originally Posted by Snow View Post
    "^" , float?

    C/C++ "^" . - pow().
    , !

  7. #7
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , - r*r; pow , .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  8. #8
    Ronnie James Dio Snow's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 8,221
    Quote Originally Posted by Bombera View Post
    , - r*r; pow , .
    , . , , .

    ! (;
    MSI B550i Gaming Edge Wifi | Ryzen 9 5900X [Thermalright AXP-100C65 + Noctua A9x14] | G.Skill 2x16GB F4-3200C16Q-32GTZR | AMD RX 6800XT | EVO970 500GB + EVO850 250GB + EVO850 500GB + DS119j | Corsair SF750 Platinum | ASUS MG279Q | Razer DeathAdder V2 Pro | Keychron K6 Modded | SligerSM550

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |