Jump to content

Recommended Posts

  • 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
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

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.