Jump to content
Forgot your email address? ×
×
×
  • Create New...
  • 0

C++ test


flygun

Question

  • Former Staff

hello dev I started to study c++ alone so of course i got some questions

 

if i got this code

#include "stdafx.h"			
#include "iostream"			
#include "string"			
#include "sstream"			
#include "stdio.h"			
#include "fstream"
using namespace std;
int main() /// main
{
    char key[] = "yes";
    char kea[] = "no";
    char buffer[80];
    string name;
    int a, b, c;
    b = 2014;
    cout << "Hello..!!" << endl;
    cout << "please type your name" << endl;
    cin >> name;
    cout << "OK " << name << " What year you were born??" << endl;
    cin >> a;
    if (a <= 1940)
    {
        cout << "You are too old to use a computer";
        system("pause");
        return 0;
    }
    else if (a >= 2010)
    {
        cout << "You are too young to use computer" ;
        system("pause");
        return 0;
    }
    else
    c = b - a;
    cout << "You are " << c << " Years old" << endl;
    do {
        printf("Do you want to save the age and the name ? (yes/no)");
        fflush(stdout);
        scanf_s("%79s", buffer);
    } while (strcmp(key, buffer) != 0);
    ofstream age;
    age.open("ages.txt", ios::app);
            if (age.is_open())
            {
                age << name << "     " << c << endl;
                age.close();
                system("pause");
                return 0;
            }
    system("pause");
    return 0;
}

this work till now fine ....but this part

do {
		printf("Do you want to save the age and the name ? (yes/no)");
		fflush(stdout);
		scanf_s("%79s", buffer);
	} while (strcmp(key, buffer) != 0);

this part above only check it the string is "yes" and then save the name and the age

	char key[] = "yes";
	char kea[] = "no";

in summary i just want the program to see if the user want to save or not then act like the user say

 

sorry for bad English

 

Best regards

     FlyGun .!! :)

 

Link to comment
  • Answers 0
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Announcements

  • -15% Discount in Metin2 Dev Store (01/10/2021 => 31/12/2021) => Code => 15_PCT_OCT_TO_DEC_2021


  • Read our Rules
  • Activity

    1. 1

      [HELP] Costume bonusing with item not working

    2. 10

      Fix Taskbar Highlight Python

    3. 13

      Reduce server memory usage

    4. 87

      How To Enchant & Transform Costume

    5. 2

      Old m2 function

  • Recently Browsing

    • No registered users viewing this page.

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.