Hello daniweb!
i have recently started to learn c++ and have made a few programs, (a hello world and a multiplication program) following some tutorials. So i decided to try and make my own, but it did not go well. After debugging in microsoft visual c++ 2010 i got loads of errors, and i am not sure what i have done wrong.

//Revision times generator

#include <iostream>
#include <string>
using namespace std;

int main () {

    string day;

    cout << "What day is it today?";
    getline(cin, day);
    if (day == 'monday') {
        cout << "you should revise computing today." << endl;
    } else if (day == 'tuesday') {
        cout << "you should revise math today." << endl;
    } else if (day == 'wednesday') {
        cout << "you should revise biology today." << endl;
    } else if (day == 'thursday') {
        cout << "you sould revise modern studies today." << endl;
    } else if (day == 'friday') {
        cout << "you should revise french today." << endl;
    } else if (day == 'saturday') {
        cout << "you should revise chemistry today." << endl;
    } else if (day == 'sunday') {
        cout << "take a break today." << endl;
    } else
        cout << "no valid day entered." << endl;

    system ("pause");
    return 0;
}

any help would be great.

Dani AI

Generated

— the compile problems come from using single quotes around multi-character text. In C++ single quotes create character (or implementation-defined multi-character) literals, while double quotes create string literals. A std::string must be compared to a string literal (double quotes) or another std::string; comparing it to a single-quoted multi-character literal will not match any proper overload and produces errors. was right to flag the quoting.

A few additional, practical points that clarify and harden the program:

  • Input comparisons are case-sensitive and often include stray spaces. Normalize input (trim whitespace and convert to lowercase) before matching.
  • Long if/else chains are fragile. Use a container (std::map or std::unordered_map) to map weekday names to messages — it is shorter and easier to maintain.
  • Avoid platform-specific calls like system("pause") in learning code; run the program from a terminal or use a simple portable pause (for example, std::cin.get() after prompting).
  • Prefer keeping using namespace std; out of larger code to avoid name collisions.

A concise, robust pattern (structure only; messages replaced with placeholders) — normalise input, look up the day, print the result:

#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cctype>

static std::string normalize(std::string s) {
    const char* ws = " \t\n\r";
    auto start = s.find_first_not_of(ws);
    if (start == std::string::npos) return "";
    auto end = s.find_last_not_of(ws);
    s = s.substr(start, end - start + 1);
    std::transform(s.begin(), s.end(), s.begin(),
                   [](unsigned char c){ return std::tolower(c); });
    return s;
}

// ... in main(): read line, normalize(day), find in map, print message or "No valid day entered."

Echoing : start with a gentle, example-driven introduction to C++, focus first on I/O, types, and the standard library, then progress to modern C++ practices and more advanced references. Small exercises and reading simple, well-written programs accelerate learning more than chasing tutorials alone.

Recommended Answers

All 5 Replies

this

'monday'

should be

"monday"

Strings are enclosed with double quotes not single quotes...

If your learning C++ then please get yourself a good book on the subject...Tutorials just don't cut it.

thanks for your help, could you reccomend any good c++ books?

thanks for your help, could you reccomend any good c++ books?

Depends...Are you a complete programming rookie or do you know how to program in other languages besides C++.

i'm a complete rookie

i'm a complete rookie

Then don't get Accelerated C++ as a first book...as a second yes but not as a first..

I think you can still get "Teach Yourself C++ in 21 days" by googling...The book is a bit dated but its still a good read for the rookie.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.