-2

Him and thank you for the help in advance. I was just doing one of my assignments for school and I stumbled upon a problem. It's a simple bill calculator that differentiates you between a premium user and a regular one and calculates your bill based on the different rates. I thought I had finished it but now I'm getting this error. Please any help will do, just want to get this all said and done with.

Debug Error!
Program : ...\ConsoleApplication12.exe
Module : ...\ConsoleApplication12.exe

Run-Time Check Failure #3 - T

enter image description here

#include <iostream>
#include<iomanip>

using namespace std;
int main() {
const float Regular = 10;
const float Premium = 25;
const float RRate = .2;
const float DRate = .1;
const float NRate = .05;
int account;
int Rminutes;
int Dminutes;
int Nminutes;
int totalmin;
float Dcharge;
float Ncharge;
float total;
char service;
cout << "Enter the account number\n";
cin >> account;
cout << "Enter the service code\n";
cin >> service;

switch(service)
{case'r':
case'R':
    cout << "Please enter the total amount of minutes used\n";
        cin >> Rminutes;
        if (Rminutes > 50) {
            total = (Rminutes - 50)*RRate + Regular;
        }
        else {
            total = Regular;
        }
        break;
case'P':
case'p':
    cout << "Please enter how many minutes were used during the day\n";
    cin >> Dminutes;
    cout << "Please enter how many minutes were used during the night\n";
    cin >> Nminutes;
    if (Dminutes > 75) {
        Dcharge = (Dminutes - 75)*DRate;
    }
    if (Nminutes > 100) {
        Ncharge = (Nminutes - 100)*NRate;
    }
    total = Premium + Dcharge + Ncharge;
    break;
default:
    cout << "Invalid service code\n";
    return 1;
    break;
}
totalmin = Rminutes + Dminutes + Nminutes;
cout << "Your account number is:" << account;
cout << "Your type of service is:" << service;
cout << "your total minutes used was" << totalmin;
cout << "your bill is" << total;
return 0;
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
deawsum
  • 5
  • 3
  • 6
    You need to narrow this down to an [mcve](https://stackoverflow.com/help/mcve). – Jason Nov 05 '15 at 23:02
  • I just run the code on Dev C++ and it worked... xD – Konstantinos Kamaropoulos Nov 05 '15 at 23:03
  • The code works for me too, output is: Your account number is:1Your type of service is:Ryour total minutes used was23your bill is10 – anthr Nov 05 '15 at 23:04
  • Possible duplicate of [Run-Time Check Failure #3 - The variable 'result' is being used without being initialized](http://stackoverflow.com/questions/28973043/run-time-check-failure-3-the-variable-result-is-being-used-without-being-in) – J... Nov 05 '15 at 23:08

1 Answers1

0

Try to define initialization values for all your variables. This code worked on Visual Studio too:

#include <iostream>
#include<iomanip>

using namespace std;
int main() {
    const float Regular = 10;
    const float Premium = 25;
    const float RRate = .2;
    const float DRate = .1;
    const float NRate = .05;
    int account=0;
    int Rminutes=0;
    int Dminutes=0;
    int Nminutes=0;
    int totalmin=0;
    float Dcharge=0;
    float Ncharge=0;
    float total=0;
    char service=0;
    cout << "Enter the account number\n";
    cin >> account;
    cout << "Enter the service code\n";
    cin >> service;

    switch (service)
    {
    case'r':
    case'R':
        cout << "Please enter the total amount of minutes used\n";
        cin >> Rminutes;
        if (Rminutes > 50) {
            total = (Rminutes - 50)*RRate + Regular;
        }
        else {
            total = Regular;
        }
        break;
    case'P':
    case'p':
        cout << "Please enter how many minutes were used during the day\n";
        cin >> Dminutes;
        cout << "Please enter how many minutes were used during the night\n";
        cin >> Nminutes;
        if (Dminutes > 75) {
            Dcharge = (Dminutes - 75)*DRate;
        }
        if (Nminutes > 100) {
            Ncharge = (Nminutes - 100)*NRate;
        }
        total = Premium + Dcharge + Ncharge;
        break;
    default:
        cout << "Invalid service code\n";
        return 1;
        break;
    }
    totalmin = Rminutes + Dminutes + Nminutes;
    cout << "Your account number is: " << account << "\n";
    cout << "Your type of service is: " << service << "\n";
    cout << "your total minutes used was " << totalmin << "\n";
    cout << "your bill is " << total;
    system("PAUSE");
    return 0;
}